fakeweb icon indicating copy to clipboard operation
fakeweb copied to clipboard

NetConnectNotAllowedError reports the URI different than what is acually being matched.

Open weshatheleopard opened this issue 10 years ago • 3 comments

The problem is that prior to matching, the URI is passed through normalize_uri which mangles it.

For example:

> require 'fakeweb'
> FakeWeb.allow_net_connect = false
> FakeWeb.register_uri(:get, /http:\/\/good\.com\/\?a=1\&b=2/, :body => "good")
> FakeWeb.register_uri(:get, /http:\/\/bad\.com\/\?b=1\&a=2/, :body => "bad")

> Net::HTTP.get('good.com', '/?a=1&b=2')
"good"
> Net::HTTP.get('bad.com', '/?b=1&a=2')
FakeWeb::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET http://bad.com/?b=1&a=2

which is incredibly confusing, given that error message contains exactly the same URL that I passed in, while in reality match happens against the URL with normalized parameters (see https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/registry.rb#L58)

weshatheleopard avatar Sep 02 '14 16:09 weshatheleopard

Looks like normalize_uri does nothing to Regexp: https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/registry.rb#L106

exchgr avatar Oct 13 '14 20:10 exchgr

normalize_uri normalizes not the match expression (/http:\/\/bad\.com\/\?b=1\&a=2/), but the source URI (http://bad.com/?b=1&a=2), which happens to be a String :stuck_out_tongue:

weshatheleopard avatar Oct 13 '14 21:10 weshatheleopard

I see. I didn't realize it was being called from multiple places. Thanks for the clarification.

exchgr avatar Oct 14 '14 02:10 exchgr