webmachine/webmachine-ruby

Default etag generation breaks during If-None-Match check (k13)

brentsnook opened this issue · 2 comments

We've found a problem with the default nil etag returned by generate_etag when a client supplies an If-None-Match header.

https://github.com/seancribbs/webmachine-ruby/blob/master/lib/webmachine/resource/callbacks.rb#L354

This will break the check at k13 because it is trying to gsub that value. Maybe this value should instead be an empty string or the etag creation/string quoting should be able to handle nil.

Found in version 1.2.2, sample stack trace below:

2014-05-23 10:15:24 ERROR: undefined method `gsub' for nil:NilClass
2014-05-23 10:15:24 ERROR: .../lib/webmachine/quoted_string.rb:31:in `escape_quotes'
.../lib/webmachine-1.2.2/lib/webmachine/quoted_string.rb:25:in `quote'
.../lib/webmachine-1.2.2/lib/webmachine/etags.rb:22:in `initialize'
.../lib/webmachine-1.2.2/lib/webmachine/etags.rb:15:in `block in new'
.../lib/webmachine-1.2.2/lib/webmachine/etags.rb:14:in `tap'
.../lib/webmachine-1.2.2/lib/webmachine/etags.rb:14:in `new'
.../lib/webmachine-1.2.2/lib/webmachine/decision/flow.rb:326:in `k13'
.../lib/webmachine-1.2.2/lib/webmachine/decision/fsm.rb:27:in `block (2 levels) in run'
.../lib/webmachine-1.2.2/lib/webmachine/decision/fsm.rb:47:in `handle_exceptions'
.../lib/webmachine-1.2.2/lib/webmachine/decision/fsm.rb:27:in `block in run'
.../lib/webmachine-1.2.2/lib/webmachine/decision/fsm.rb:25:in `loop'
.../lib/webmachine-1.2.2/lib/webmachine/decision/fsm.rb:25:in `run'
.../lib/webmachine-1.2.2/lib/webmachine/dispatcher.rb:45:in `block in dispatch'

This should be verifiable with a simple test. Thank you for reporting!

Closing in favor of #167