Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix issue where empty query key causes a `TypeError` #352

Merged
merged 2 commits into from Jan 16, 2014

Conversation

Projects
None yet
2 participants
Contributor

JonRowe commented Jan 9, 2014

As seen in the real world (tm), sometimes queries have values but no keys which
causes webmock to blow up with a TypeError:

lib/webmock/util/query_mapper.rb:187:in `dup': can't dup NilClass (TypeError)
  from ./gems/webmock-1.15.2/lib/webmock/util/query_mapper.rb:187:in `block in values_to_query'
  from ./gems/webmock-1.15.2/lib/webmock/util/query_mapper.rb:185:in `each'
  from ./gems/webmock-1.15.2/lib/webmock/util/query_mapper.rb:185:in `values_to_query'
  from ./gems/webmock-1.15.2/lib/webmock/util/uri.rb:18:in `block in <class:URI>'
  from ./gems/webmock-1.15.2/lib/webmock/util/uri.rb:33:in `yield'
  from ./gems/webmock-1.15.2/lib/webmock/util/uri.rb:33:in `normalize_uri'
  from ./gems/webmock-1.15.2/lib/webmock/request_signature.rb:10:in `initialize'
  from ./gems/webmock-1.15.2/lib/webmock/http_lib_adapters/net_http.rb:290:in `new'
  from ./gems/webmock-1.15.2/lib/webmock/http_lib_adapters/net_http.rb:290:in `request_signature_from_request'
  from ./gems/webmock-1.15.2/lib/webmock/http_lib_adapters/net_http.rb:75:in `request'
  from ./gems/net-http-persistent-2.9/lib/net/http/persistent.rb:986:in `request'
  from ./bundler/gems/mechanize-3c0a3714926e/lib/mechanize/http/agent.rb:259:in `fetch'
  from ./bundler/gems/mechanize-3c0a3714926e/lib/mechanize.rb:440:in `get'

This resolves that by casting nil to a string as with Symbol.

Owner

bblimke commented Jan 9, 2014

Is it allowed to have blank query keys in the url according to the spec?

Contributor

JonRowe commented Jan 9, 2014

A query string is any character between ? and # citation with the only further thing said "often used to carry identifying information in the form of 'key=value' pair" however, URI.parse handles it, and it's seen in the wild, and as a testing framework I think this should be handled gracefully, and this is the best effort at that.

An alternative would be to validate the format of the query string before attempting to split it into key value pairs, as the query string could then just be left alone.

Owner

bblimke commented Jan 16, 2014

Ok, looks good. Cheers.

@bblimke bblimke added a commit that referenced this pull request Jan 16, 2014

@bblimke bblimke Merge pull request #352 from JonRowe/fixup_query_mapper
Fix issue where empty query key causes a `TypeError`
3c670aa

@bblimke bblimke merged commit 3c670aa into bblimke:master Jan 16, 2014

1 check failed

default The Travis CI build could not complete due to an error
Details

@JonRowe JonRowe deleted the JonRowe:fixup_query_mapper branch Jan 16, 2014

Contributor

JonRowe commented Jan 16, 2014

Thanks :)

Owner

bblimke commented Jan 16, 2014

Released as 1.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment