fakeweb icon indicating copy to clipboard operation
fakeweb copied to clipboard

URI encoding causing an issue

Open jonleighton opened this issue 15 years ago • 2 comments

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

jonleighton avatar Jul 28 '10 14:07 jonleighton

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?

chrisk avatar Aug 16 '10 02:08 chrisk

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.)

jonleighton avatar Aug 25 '10 18:08 jonleighton