Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

do not break params filtering on nil values #165

Merged
merged 1 commit into from

2 participants

@nashby nashby referenced this pull request in rails/rails
Merged

do not break params filtering on nil values #12159

@rafaelfranca rafaelfranca merged commit 1d51d5e into from
@nashby nashby deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 13, 2013
  1. @nashby
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.