Skip to content
Browse files

do not break params filtering on nil values

  • Loading branch information...
1 parent 4f361c8 commit 559268d4b6230f1630fb6977e988ba273a465d16 @nashby nashby committed Sep 13, 2013
Showing with 10 additions and 1 deletion.
  1. +1 −1 lib/action_controller/parameters.rb
  2. +9 −0 test/parameters_permit_test.rb
View
2 lib/action_controller/parameters.rb
@@ -179,7 +179,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] == []
# Declaration {:comment_ids => []}.
View
9 test/parameters_permit_test.rb
@@ -95,6 +95,15 @@ def assert_filtered_out(params, key)
assert !permitted.has_key?(: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
+
# --- key to empty array -----------------------------------------------------
test 'key to empty array: empty arrays pass' do

0 comments on commit 559268d

Please sign in to comment.
Something went wrong with that request. Please try again.