diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-04-15 09:08:47 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-04-15 09:09:50 -0600 |
commit | 94a1edbc023fd82bf96705d86abc85d2eab14ba3 (patch) | |
tree | 762f16eca798d76e047640b6d7a85f22c2ba0b48 /actionpack/lib | |
parent | b1f4c4bbcfe31999636130dea478c076ec595fe7 (diff) | |
download | rails-94a1edbc023fd82bf96705d86abc85d2eab14ba3.tar.gz rails-94a1edbc023fd82bf96705d86abc85d2eab14ba3.tar.bz2 rails-94a1edbc023fd82bf96705d86abc85d2eab14ba3.zip |
Filter scalar values when params permit hashes or arrays
This brings the behavior more inline with other similar cases, such as
receiving a hash when an array of scalars was expected. Prior to this
commit, the key would be present, but the value would be `nil`
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 64672de57e..f9b80dd805 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -756,6 +756,10 @@ module ActionController end end + def non_scalar?(value) + value.is_a?(Array) || value.is_a?(Parameters) + end + EMPTY_ARRAY = [] def hash_filter(params, filter) filter = filter.with_indifferent_access @@ -770,7 +774,7 @@ module ActionController array_of_permitted_scalars?(self[key]) do |val| params[key] = val end - else + elsif non_scalar?(value) # Declaration { user: :name } or { user: [:name, :age, { address: ... }] }. params[key] = each_element(value) do |element| element.permit(*Array.wrap(filter[key])) |