Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weshatheleopard opened this issue Sep 2, 2014 · 3 comments

Comments

@weshatheleopard
Copy link

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)

@exchgr
Copy link

exchgr commented Oct 13, 2014

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

@weshatheleopard
Copy link
Author

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 😛

@exchgr
Copy link

exchgr commented Oct 14, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants