diff options
Diffstat (limited to 'lib/rack/query_parser.rb')
-rw-r--r-- | lib/rack/query_parser.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/rack/query_parser.rb b/lib/rack/query_parser.rb index 17b77128..be74bc06 100644 --- a/lib/rack/query_parser.rb +++ b/lib/rack/query_parser.rb @@ -102,8 +102,7 @@ module Rack child_key = $1 params[k] ||= [] raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array) - first_key = child_key.gsub(/[\[\]]/, ' ').split.first - if params_hash_type?(params[k].last) && !params[k].last.key?(first_key) + if params_hash_type?(params[k].last) && !params_hash_has_key?(params[k].last, child_key) normalize_params(params[k].last, child_key, v, depth - 1) else params[k] << normalize_params(make_params, child_key, v, depth - 1) @@ -135,6 +134,18 @@ module Rack obj.kind_of?(@params_class) end + def params_hash_has_key?(hash, key) + return false if key =~ /\[\]/ + + key.split(/[\[\]]+/).inject(hash) do |h, part| + next h if part == '' + return false unless params_hash_type?(h) && h.key?(part) + h[part] + end + + true + end + def unescape(s) Utils.unescape(s) end |