Skip to content

Commit

Permalink
Fixed incorrect parsing of query parameters with mixed-depth nesting …
Browse files Browse the repository at this point in the history
…inside an array [#1622 state:resolved]

Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
  • Loading branch information
mrj authored and wycats committed Jan 1, 2009
1 parent 373e94a commit ea20901
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions actionpack/lib/action_controller/url_encoded_pair_parser.rb
Expand Up @@ -70,11 +70,12 @@ def bind(key, value)
top[-1][key] = value
else
top << {key => value}.with_indifferent_access
push top.last
value = top[key]
end
push top.last
return top[key]
else
top << value
return value
end
elsif top.is_a? Hash
key = CGI.unescape(key)
Expand All @@ -84,12 +85,10 @@ def bind(key, value)
else
raise ArgumentError, "Don't know what to do: top is #{top.inspect}"
end

return value
end

def type_conflict!(klass, value)
raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value. (The parameters received were #{value.inspect}.)"
end
end
end
end
1 change: 1 addition & 0 deletions actionpack/test/controller/request_test.rb
Expand Up @@ -441,6 +441,7 @@ def test_deep_query_string_with_array
def test_deep_query_string_with_array_of_hash
assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10'))
assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=10'))
assert_equal({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][v][w]=10'))
end

def test_deep_query_string_with_array_of_hashes_with_one_pair
Expand Down

0 comments on commit ea20901

Please sign in to comment.