Permalink
Browse files

Merge pull request #12159 from nashby/issue-12149

do not break params filtering on nil values
  • Loading branch information...
2 parents 8f57b22 + 1d375e5 commit b3a9cac18f68a7c7d740089bb208481332bb4ec7 @rafaelfranca rafaelfranca committed Sep 12, 2013
@@ -421,7 +421,7 @@ def hash_filter(params, filter)
# 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: [] }.
@@ -107,6 +107,15 @@ def assert_filtered_out(params, key)
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)

0 comments on commit b3a9cac

Please sign in to comment.