Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

correct handling for incomplete hash/array parameters

  • Loading branch information...
commit 5a5aee3612f3d1c56424ad387ada56174fd94828 1 parent 1f47a44
@vspy vspy authored
Showing with 14 additions and 1 deletion.
  1. +2 −1  lib/rack/request.rb
  2. +2 −0  lib/rack/utils.rb
  3. +10 −0 test/spec_utils.rb
View
3  lib/rack/request.rb
@@ -192,8 +192,9 @@ def GET
if @env["rack.request.query_string"] == query_string
@env["rack.request.query_hash"]
else
+ p = parse_query(query_string)
@env["rack.request.query_string"] = query_string
- @env["rack.request.query_hash"] = parse_query(query_string)
+ @env["rack.request.query_hash"] = p
end
end
View
2  lib/rack/utils.rb
@@ -109,6 +109,8 @@ def normalize_params(params, name, v = nil)
if after == ""
params[k] = v
+ elsif after == "["
+ params[name] = v
elsif after == "[]"
params[k] ||= []
raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
View
10 test/spec_utils.rb
@@ -157,6 +157,16 @@ def kcodeu
should.equal "foo" => [""]
Rack::Utils.parse_nested_query("foo[]=bar").
should.equal "foo" => ["bar"]
+ Rack::Utils.parse_nested_query("foo[]=bar&foo").
+ should.equal "foo" => nil
+ Rack::Utils.parse_nested_query("foo[]=bar&foo[").
+ should.equal "foo" => ["bar"], "foo[" => nil
+ Rack::Utils.parse_nested_query("foo[]=bar&foo[=baz").
+ should.equal "foo" => ["bar"], "foo[" => "baz"
+ Rack::Utils.parse_nested_query("foo[]=bar&foo[]").
+ should.equal "foo" => ["bar", nil]
+ Rack::Utils.parse_nested_query("foo[]=bar&foo[]=").
+ should.equal "foo" => ["bar", ""]
Rack::Utils.parse_nested_query("foo[]=1&foo[]=2").
should.equal "foo" => ["1", "2"]
Please sign in to comment.
Something went wrong with that request. Please try again.