chrisk / fakeweb

Ruby test helper for injecting fake responses to web requests
MIT License
1.09k stars 134 forks source link

URI encoding causing an issue #16

Open jonleighton opened 14 years ago

jonleighton commented 14 years ago

Hiya,

I have a URI like this:

http:://test.host/resource?date=2010-07-28T14:19:47Z

When Net::HTTP sends the request, it has turned it into:

http:://test.host/resource?date=2010-07-28T14%3A19%3A47Z

Which then doesn't get matched by FakeWeb.

If I put the parameter through CGI.escape then that solves the problem for me, but it'd be nice if FakeWeb worked that out itself.

Cheers

chrisk commented 14 years ago

I'm having trouble reproducing this. Net::HTTP seems to send out that request as-is, with no escaping of the query string. Here's my test (which passes):

def test_query_param_encoding
  FakeWeb.register_uri(:get, "http://example.com/?date=2010-07-28T14:19:47Z", :body => "body")
  response = Net::HTTP.start("example.com") { |query| query.get("/?date=2010-07-28T14:19:47Z") }
  assert_equal "body", response.body
end

Are you sure it's Net::HTTP that's doing the encoding?

jonleighton commented 14 years ago

Hiya,

Thanks for your response. I agree with you that the above test works fine. In my real-world app I am actually using rest-client (http://github.com/archiloque/rest-client) to send requests, so I can only assume that rest-client is itself changing the URI before sending it to Net::HTTP.

However, it would be quite nice if Fakeweb could recognise CGI encoding in URIs and treat in indifferently. In other words, it would be nice if the following modified test passed (which would have solved my problem):

def test_query_param_encoding
  FakeWeb.register_uri(:get, "http://example.com/?date=2010-07-28T14:19:47Z", :body => "body")
  response = Net::HTTP.start("example.com") { |query| query.get("/?date=2010-07-28T14%3A19%3A47Z") }
  assert_equal "body", response.body
end

(And vice versa I guess, though that is less important as you are unlikely to specify a CGI encoded URL when writing your test.)