Skip to content

Commit

Permalink
Don't append an ampersand when params are empty (rack#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbilharz authored and perlun committed Apr 26, 2017
1 parent 5c3fe94 commit ac30234
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def env_for(path, env)
if params = env[:params]
params = parse_nested_query(params) if params.is_a?(String)

uri.query = [uri.query, build_nested_query(params)].compact.join("&")
uri.query = [uri.query, build_nested_query(params)].compact.reject { |v| v == '' }.join("&")
end
elsif !env.has_key?(:input)
env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded"
Expand Down
5 changes: 5 additions & 0 deletions spec/rack/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
expect(last_request.query_string).to eq("a=1&b=2&c=3&e=4&d=5+%20")
end

it "does not rewrite a GET query string when :params is empty" do
request "/foo?a=1&b=2&c=3&e=4&d=5", :params => {}
last_request.query_string.should == "a=1&b=2&c=3&e=4&d=5"
end

it "does not overwrite multiple query string keys" do
request "/foo?a=1&a=2", :params => { :bar => 1 }
expect(last_request.query_string).to eq("a=1&a=2&bar=1")
Expand Down

0 comments on commit ac30234

Please sign in to comment.