1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Array parameters should not contain nil values.

This commit is contained in:
Aaron Patterson 2012-06-10 22:44:54 -05:00
parent 65d584c35b
commit 24894fc130
2 changed files with 8 additions and 2 deletions

View file

@ -267,17 +267,19 @@ module ActionDispatch
# Remove nils from the params hash
def deep_munge(hash)
keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }
hash.each_value do |v|
case v
when Array
v.grep(Hash) { |x| deep_munge(x) }
v.compact!
when Hash
deep_munge(v)
end
end
keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }
hash
end

View file

@ -89,6 +89,10 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
end
def test_array_parses_without_nil
assert_parses({"action" => ['1']}, "action[]=1&action[]")
end
test "query string with empty key" do
assert_parses(
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },