Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #12159 from nashby/issue-12149

do not break params filtering on nil values
  • Loading branch information...
commit b3a9cac18f68a7c7d740089bb208481332bb4ec7 2 parents 8f57b22 + 1d375e5
@rafaelfranca rafaelfranca authored
View
2  actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -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: [] }.
View
9 actionpack/test/controller/parameters/parameters_permit_test.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.