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

do not break params filtering on nil values

closes #12149
This commit is contained in:
Vasiliy Ermolovich 2013-09-07 15:16:45 +03:00
parent c989a18a74
commit 1d375e59f1
2 changed files with 10 additions and 1 deletions

View file

@ -421,7 +421,7 @@ module ActionController
# Slicing filters out non-declared keys.
slice(*filter.keys).each do |key, value|
return unless value
next unless value
if filter[key] == EMPTY_ARRAY
# Declaration { comment_ids: [] }.

View file

@ -107,6 +107,15 @@ class ParametersPermitTest < ActiveSupport::TestCase
assert_equal [], permitted[:id]
end
test 'do not break params filtering on nil values' do
params = ActionController::Parameters.new(a: 1, b: [1, 2, 3], c: nil)
permitted = params.permit(:a, c: [], b: [])
assert_equal 1, permitted[:a]
assert_equal [1, 2, 3], permitted[:b]
assert_equal nil, permitted[:c]
end
test 'key to empty array: arrays of permitted scalars pass' do
[['foo'], [1], ['foo', 'bar'], [1, 2, 3]].each do |array|
params = ActionController::Parameters.new(id: array)