Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

wrote a test for weird characters in query string #214

Closed
wants to merge 1 commit into from

3 participants

@goblin

When stub_request contains weird characters like + and / in the query string,
the error messages returned by rspec ("You can stub this request with")
contain "%20"s in the URL instead of %2B or %2F. This tests for that.

The test fails. I don't yet know how to fix the code to make it pass

@goblin goblin wrote a test for weird characters in query string
When stub_request contains weird characters like + and / in the query string,
the error messages returned by rspec ("You can stub this request with")
contain "%20"s in the URL instead of %2B or %2F. This tests for that.
1596f6b
@bblimke
Owner

Thank you for this spec. I'll investigate this as soon as I can.

@bblimke
Owner

I'm sorry for the delay with this pull request. I'm still not sure what's the best way to handle + in url provided to webmock. as '+' or as space.

@myronmarston
Collaborator

FWIW, I've seen a fair bit of confusion (and, on occasion, been personally confused myself) about + in URLs. The TL;DR is that I think + should be treated as a space in the query string but not in the path. See this sinatra discussion for more.

@bblimke
Owner

+ in query params is not treated by WebMock as space anymore and is now encoded to %2B.

Thank you!

@bblimke bblimke closed this
@bblimke
Owner

ok, maybe I was too fast with that change. @myronmarston so from what you wrote, when I see + in query params, it should be treated as a space right? Does that mean the test provided by @goblin is invalid?

@bblimke bblimke reopened this
@myronmarston
Collaborator

ok, maybe I was too fast with that change. @myronmarston so from what you wrote, when I see + in query params, it should be treated as a space right?

When the query params are parsed, the standard is to treat them as being www-form-urlencoded -- which means a query string like ?q=a+b&c=5 would parse to { "q" => "a b", "c" => "5" }.

As I interpret it, + should only be treated as a space when parsing the query string as params. When considering the entire URI (as @goblin's test does), I don't think it should be treated in any particular way.

@bblimke
Owner

@myronmarston in @goblin's test, + appears only in the query string, not in the path, so the test assertions seem invalid.

@myronmarston
Collaborator

I agree the test looks invalid to me. My point was that his test is only looking at the entire URI so it shouldn't be treating any part in any particular way.

@goblin

So my test is only checking the output message from webmock in the case when it tells the user how to stub it.

When I had my query with a +, it failed a test, so I took the string given to me by "You should stub the request with", pasted it into my test, and it was still failing. I had to manually change the %20 into %2B to get the test to pass (all that if I remember correctly... it was a while ago)

@goblin

Perhaps it should just tell to stub with a + rather than %2B... dunno

@bblimke bblimke closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 4, 2012
  1. @goblin

    wrote a test for weird characters in query string

    goblin authored
    When stub_request contains weird characters like + and / in the query string,
    the error messages returned by rspec ("You can stub this request with")
    contain "%20"s in the URL instead of %2B or %2F. This tests for that.
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 0 deletions.
  1. +17 −0 spec/acceptance/em_http_request/em_http_request_spec.rb
View
17 spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -205,6 +205,23 @@ def response(resp)
http_request(:post, "http://www.example.com").body.bytesize.should == body.bytesize
end
+ context "in presence of special characters in the request" do
+ it "should correctly tell the user how to stub" do
+ WebMock.disable_net_connect!
+ begin
+ http_request(:get, "http://www.example.com/?foo=a+/b=c")
+ rescue WebMock::NetConnectNotAllowedError => e
+ e.message.should match /Unregistered request: GET http:\/\/www\.example\.com\/\?foo=a%2B\/b=c/m
+ e.message.should match /stub_request\(:get, "http:\/\/www\.example\.com\/\?foo=a%2B\/b=c"\)/m
+ rescue Exception => e
+ fail "unknown exception #{e.message}"
+ else
+ fail "unknown error"
+ end
+
+ end
+ end
+
describe "mocking EM::HttpClient API" do
let(:uri) { "http://www.example.com/" }
Something went wrong with that request. Please try again.