Permalink
Browse files

Merge pull request #12159 from nashby/issue-12149

do not break params filtering on nil values
  • Loading branch information...
1 parent d107a84 commit e6ca38f25cd972321159e90b5a43dd50a5ae92d5 @rafaelfranca rafaelfranca committed Sep 12, 2013
View
6 actionpack/CHANGELOG.md
@@ -1,5 +1,11 @@
## unreleased ##
+* Do not break params filtering on `nil` values.
+
+ Fixes #12149.
+
+ *Vasiliy Ermolovich*
+
* Fix `excerpt` when `:separator` is `nil`.
*Paul Nikitochkin*
View
2 actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -416,7 +416,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)

0 comments on commit e6ca38f

Please sign in to comment.