diff options
author | Xavier Noria <fxn@hashref.com> | 2013-12-21 13:41:46 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-12-21 13:47:26 +0100 |
commit | 269424b0bb8c103418d8a948bf88ca708350ebff (patch) | |
tree | 584eb893d2e9fec9a66947e3f45bfdab4a47f76b /actionpack/lib/action_controller | |
parent | e219bf0ebc38ac15ef95b41897653fc11fc78873 (diff) | |
download | rails-269424b0bb8c103418d8a948bf88ca708350ebff.tar.gz rails-269424b0bb8c103418d8a948bf88ca708350ebff.tar.bz2 rails-269424b0bb8c103418d8a948bf88ca708350ebff.zip |
refactors AC::Parameters#fetch
AC::Parameters#fetch was refactored in 7171111 to prevent self mutation, but
in doing so it hardcodes logic #convert_hashes_to_parameters is supposed to
encapsulate.
Better leave the delegation, and add a way to avoid mutating self in there.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index a3ac15a1d2..1c06d9a7db 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -284,14 +284,7 @@ module ActionController # params.fetch(:none, 'Francesco') # => "Francesco" # params.fetch(:none) { 'Francesco' } # => "Francesco" def fetch(key, *args) - value = super - # Don't rely on +convert_hashes_to_parameters+ - # so as to not mutate via a +fetch+ - if value.is_a?(Hash) - value = self.class.new(value) - value.permit! if permitted? - end - value + convert_hashes_to_parameters(key, super, false) rescue KeyError raise ActionController::ParameterMissing.new(key) end @@ -329,9 +322,9 @@ module ActionController end private - def convert_hashes_to_parameters(key, value) + def convert_hashes_to_parameters(key, value, assign_if_converted=true) converted = convert_value_to_parameters(value) - self[key] = converted unless converted.equal?(value) + self[key] = converted if assign_if_converted && !converted.equal?(value) converted end |