From aeecb1809f82f6793b4c406115ce7b6e1e90bde1 Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Fri, 15 Mar 2013 16:01:48 -0400 Subject: [PATCH] Don't clobber uri.query when it's present. --- lib/rack/test.rb | 4 ++-- spec/rack/test_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/rack/test.rb b/lib/rack/test.rb index 8877e7f..e33bf1b 100644 --- a/lib/rack/test.rb +++ b/lib/rack/test.rb @@ -209,8 +209,8 @@ def env_for(path, env) # merge :params with the query string if params = env[:params] params = parse_nested_query(params) if params.is_a?(String) - params.update(parse_nested_query(uri.query)) - uri.query = build_nested_query(params) + + uri.query = [uri.query, build_nested_query(params)].compact.join("&") end elsif !env.has_key?(:input) env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded" diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb index a9e2136..c60b2cd 100644 --- a/spec/rack/test_spec.rb +++ b/spec/rack/test_spec.rb @@ -132,6 +132,11 @@ expect(last_request.query_string).to eq("a=1&a=2&bar=1") end + it "does not overwrite multiple query string keys" do + request "/foo?a=1&a=2", :params => { :bar => 1 } + last_request.query_string.should == "a=1&a=2&bar=1" + end + it "accepts params and builds url encoded params for POST requests" do request "/foo", :method => :post, :params => {:foo => {:bar => "1"}} expect(last_request.env["rack.input"].read).to eq("foo[bar]=1")