Skip to content

Commit

Permalink
Fix normalize_params parsing arrays of hashes
Browse files Browse the repository at this point in the history
Account for child_key being a key representing a nested hash
Closes rack#951
  • Loading branch information
Graham Conzett authored and rthbound committed Mar 5, 2016
1 parent 93d1de7 commit 7f00781
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rack/query_parser.rb
Expand Up @@ -96,7 +96,8 @@ def normalize_params(params, name, v, depth)
child_key = $1
params[k] ||= []
raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
if params_hash_type?(params[k].last) && !params[k].last.key?(child_key)
first_key = child_key.gsub(/[\[\]]/, ' ').split.first
if params_hash_type?(params[k].last) && !params[k].last.key?(first_key)
normalize_params(params[k].last, child_key, v, depth - 1)
else
params[k] << normalize_params(make_params, child_key, v, depth - 1)
Expand Down
2 changes: 1 addition & 1 deletion test/spec_utils.rb
Expand Up @@ -311,7 +311,7 @@ def initialize(*)
message.must_equal "value must be a Hash"
end

should 'perform the inverse function of #parse_nested_query' do
it 'perform the inverse function of #parse_nested_query' do
[{"foo" => nil, "bar" => ""},
{"foo" => "bar", "baz" => ""},
{"foo" => ["1", "2"]},
Expand Down

0 comments on commit 7f00781

Please sign in to comment.