Skip to content

Commit

Permalink
Merge pull request rack#77 from adamtanner/master
Browse files Browse the repository at this point in the history
Don't clobber request query string when passing params
  • Loading branch information
brynary committed Feb 26, 2015
2 parents acdbee6 + 55c1d95 commit 56ddeda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'rspec/core'
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new do |t|
t.pattern = "./**/*_spec.rb"
t.pattern = "spec/**/*_spec.rb"
t.ruby_opts = "-w"
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 @@
last_request.query_string.should == "a=1&b=2&c=3&e=4&d=5+%20"
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"}}
last_request.env["rack.input"].read.should == "foo[bar]=1"
Expand Down

0 comments on commit 56ddeda

Please sign in to comment.