mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master-sec'
* master-sec: Array parameters should not contain nil values.
This commit is contained in:
commit
2be40a873e
2 changed files with 8 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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" },
|
||||
|
|
Loading…
Reference in a new issue