diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 82ddfec..4f0b06b 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -480,12 +480,37 @@ class UrlEncodedRequestParameterParsingTest < Test::Unit::TestCase def test_deep_query_string_with_array_of_hashes_with_multiple_pairs assert_equal( {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b') ) end + + def test_deep_query_string_with_nested_arrays + # This works; when building the first hash at y[0], it keeps adding + # key-value pairs to the same hash until a key is repeated ('z'), causing + # a second hash to be created at y[1]. + assert_equal( + {'y' => [{'z' => '1', 'w' => '2'}, {'z' => '3', 'w' => '4'}]}, + ActionController::AbstractRequest.parse_query_parameters('y[][z]=1&y[][w]=2&y[][z]=3&y[][w]=4') + ) + + # But this doesn't work; after creating the sub-array ('y'), subsequent + # values that should be added to x[0]['y'] are instead added to a new + # array in a new hash, x[1]['y']. + assert_equal( + {'x' => [{'y' => [{'z' => '1', 'w' => '2'}]}]}, + ActionController::AbstractRequest.parse_query_parameters('x[][y][][z]=2&x[][y][][w]=1') + ) + + # This doesn't work either. + assert_equal( + {'x' => [{'y' => [{'z' => '1', 'w' => '2'}, {'z' => '3', 'w' => '4'}]}]}, + ActionController::AbstractRequest.parse_query_parameters( + 'x[][y][][z]=2&x[][y][][w]=1&x[][y][][z]=3&x[][y][][w]=4') + ) + end def test_query_string_with_nil assert_equal( { "action" => "create_customer", "full_name" => ''}, ActionController::AbstractRequest.parse_query_parameters(@query_string_with_empty) )