Skip to content

Commit

Permalink
correct handling for incomplete hash/array parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Bilyk committed Oct 23, 2013
1 parent 1f47a44 commit 5a5aee3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rack/request.rb
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/rack/utils.rb
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/spec_utils.rb
Expand Up @@ -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"]
Expand Down

0 comments on commit 5a5aee3

Please sign in to comment.