diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index d6a27b6c1aeb1993220fdde77e6fdee0e3fb6c5a..fc8dcf05b9ecfc6d2151eb794129ab565ebf25e8 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -491,5 +491,26 @@ def normalize_parameters(value) value end end + protected + + # Remove nils from the params hash + def deep_munge(hash) + hash.each_value do |v| + case v + when Array + v.grep(Hash) { |x| deep_munge(x) } + when Hash + deep_munge(v) + end + end + + keys = hash.keys.find_all { |k| hash[k] == [nil] } + keys.each { |k| hash[k] = nil } + hash + end + + def parse_query(qs) + deep_munge(super) + end end end diff --git a/actionpack/test/controller/request/query_string_parsing_test.rb b/actionpack/test/controller/request/query_string_parsing_test.rb index a31e326ddfb8bb11d68cb1d591cfd73cd73dc4fc..ac0c2f88a553256270175da68fd6f061da863338 100644 --- a/actionpack/test/controller/request/query_string_parsing_test.rb +++ b/actionpack/test/controller/request/query_string_parsing_test.rb @@ -81,7 +81,12 @@ def teardown end test "query string without equal" do - assert_parses({ "action" => nil }, "action") + assert_parses({"action" => nil}, "action") + assert_parses({"action" => {"foo" => nil}}, "action[foo]") + assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar]") + assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar][]") + assert_parses({"action" => {"foo" => nil}}, "action[foo][]") + assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]") end test "query string with empty key" do