Permalink
Browse files

I was wrong. + in query params should be treated as a space.

  • Loading branch information...
1 parent bacf823 commit 936bdd274b3e5b2422667b3ae67c29535a9d2eac @bblimke committed Mar 4, 2013
@@ -31,7 +31,7 @@ def self.to_query(hash)
string << key.to_s << '&'
else
for value in [*values]
- string << key.to_s << '=' << URI.escape(value.to_s) << '&'
+ string << key.to_s << '=' << CGI.escape(value.to_s) << '&'
end
end
end
@@ -201,7 +201,7 @@ def body_as_hash(body, content_type)
when :xml then
Crack::XML.parse(body)
else
- WebMock::Util::QueryMapper.query_to_values(body, :form_url_encoded => true)
+ WebMock::Util::QueryMapper.query_to_values(body)
end
end
@@ -81,7 +81,7 @@ def self.from_request_signature(signature)
if signature.body.to_s != ''
body = if signature.url_encoded?
- WebMock::Util::QueryMapper.query_to_values(signature.body, :form_url_encoded => true)
+ WebMock::Util::QueryMapper.query_to_values(signature.body)
else
signature.body
end
@@ -66,8 +66,7 @@ def self.query_to_values(query, options={})
value = true if value.nil?
key = Addressable::URI.unencode_component(key)
if value != true
- value.gsub!(/\+/, " ") if options[:form_url_encoded]
- value = Addressable::URI.unencode_component(value)
+ value = Addressable::URI.unencode_component(value.gsub(/\+/, " "))
end
if options[:notation] == :flat
if accumulator[key]
@@ -56,6 +56,5 @@
assert_requested(@stub_http)
end
end
-
end
@@ -20,16 +20,19 @@
begin
http_request(:get, "http://www.example.com/hello/?#{NOT_ESCAPED_PARAMS}")
rescue WebMock::NetConnectNotAllowedError => e
- e.message.should match /Unregistered request: GET http:\/\/www\.example\.com\/hello\/\?x=ab%20c&z='Stop!'%20said%20Fred%2Bm/m
- e.message.should match /stub_request\(:get, "http:\/\/www\.example\.com\/hello\/\?x=ab%20c&z='Stop!'%20said%20Fred%2Bm"\)/m
+ e.message.should match /Unregistered request: GET http:\/\/www\.example\.com\/hello\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m
+ e.message.should match /stub_request\(:get, "http:\/\/www\.example\.com\/hello\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m
end
+
+ stub_request(:get, "http://www.example.com/hello/?x=ab%20c&z='Stop!'%20said%20Fred%20m")
+ http_request(:get, "http://www.example.com/hello/?#{NOT_ESCAPED_PARAMS}")
end
end
describe "based on query params" do
it "should return stubbed response when stub declares query params as a hash" do
- stub_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).to_return(:body => "abc")
- http_request(:get, "http://www.example.com/?a[]=b&a[]=c").body.should == "abc"
+ stub_request(:get, "www.example.com").with(:query => {"a" => ["b x", "c d"]}).to_return(:body => "abc")
+ http_request(:get, "http://www.example.com/?a[]=b+x&a[]=c%20d").body.should == "abc"
end
it "should return stubbed response when stub declares query params as a hash" do
@@ -10,8 +10,8 @@
unless defined? SAMPLE_HEADERS
SAMPLE_HEADERS = { "Content-Length" => "8888", "Accept" => "application/json" }
- ESCAPED_PARAMS = "x=ab%20c&z=%27Stop%21%27%20said%20Fred%2Bm"
- NOT_ESCAPED_PARAMS = "z='Stop!' said Fred+m&x=ab c"
+ ESCAPED_PARAMS = "x=ab%20c&z=%27Stop%21%27%20said%20Fred%20m"
+ NOT_ESCAPED_PARAMS = "z='Stop!' said Fred m&x=ab c"
end
shared_examples "with WebMock" do |*adapter_info|
@@ -47,14 +47,14 @@
URIS_WITH_PATH_AND_PARAMS =
[
- "www.example.com/my path/?a=my param&b=c+d",
- "www.example.com/my%20path/?a=my%20param&b=c%2Bd",
- "www.example.com:80/my path/?a=my param&b=c+d",
- "www.example.com:80/my%20path/?a=my%20param&b=c%2Bd",
- "http://www.example.com/my path/?a=my param&b=c+d",
- "http://www.example.com/my%20path/?a=my%20param&b=c%2Bd",
- "http://www.example.com:80/my path/?a=my param&b=c+d",
- "http://www.example.com:80/my%20path/?a=my%20param&b=c%2Bd",
+ "www.example.com/my path/?a=my param&b=c d",
+ "www.example.com/my%20path/?a=my%20param&b=c%20d",
+ "www.example.com:80/my path/?a=my param&b=c d",
+ "www.example.com:80/my%20path/?a=my%20param&b=c%20d",
+ "http://www.example.com/my path/?a=my param&b=c d",
+ "http://www.example.com/my%20path/?a=my%20param&b=c%20d",
+ "http://www.example.com:80/my path/?a=my param&b=c d",
+ "http://www.example.com:80/my%20path/?a=my%20param&b=c%20d",
].sort
URIS_WITH_DIFFERENT_PORT =

0 comments on commit 936bdd2

Please sign in to comment.