Permalink
Browse files

Create an array when multiple instances of the same query parameter a…

…re used
  • Loading branch information...
kreynolds committed Feb 14, 2013
1 parent 7b535cd commit 0be8bd866bae48c5d30a2c44b305fbbe1d40ae8d
Showing with 11 additions and 3 deletions.
  1. +9 −1 lib/rack/utils.rb
  2. +2 −2 test/spec_utils.rb
View
@@ -108,7 +108,15 @@ def normalize_params(params, name, v = nil)
return if k.empty?
if after == ""
- params[k] = v
+ if cur = params[k]
+ if cur.class == Array
+ params[k] << v
+ else
+ params[k] = [cur, v]
+ end
+ else
+ params[k] = v
+ end
elsif after == "[]"
params[k] ||= []
raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
View
@@ -134,7 +134,7 @@ def kcodeu
should.equal "foo" => "\"bar\""
Rack::Utils.parse_nested_query("foo=bar&foo=quux").
- should.equal "foo" => "quux"
+ should.equal "foo" => ["bar", "quux"]
Rack::Utils.parse_nested_query("foo&foo=").
should.equal "foo" => ""
Rack::Utils.parse_nested_query("foo=1&bar=2").
@@ -170,7 +170,7 @@ def kcodeu
Rack::Utils.parse_nested_query("x[y][z][]=1").
should.equal "x" => {"y" => {"z" => ["1"]}}
Rack::Utils.parse_nested_query("x[y][z]=1&x[y][z]=2").
- should.equal "x" => {"y" => {"z" => "2"}}
+ should.equal "x" => {"y" => {"z" => ["1", "2"]}}
Rack::Utils.parse_nested_query("x[y][z][]=1&x[y][z][]=2").
should.equal "x" => {"y" => {"z" => ["1", "2"]}}

0 comments on commit 0be8bd8

Please sign in to comment.