Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 269424b0bb8c103418d8a948bf88ca708350ebff 1 parent e219bf0
@fxn fxn authored
Showing with 3 additions and 10 deletions.
  1. +3 −10 actionpack/lib/action_controller/metal/strong_parameters.rb
View
13 actionpack/lib/action_controller/metal/strong_parameters.rb
@@ -284,14 +284,7 @@ def [](key)
# 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 @@ def permitted=(new_permitted)
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
Please sign in to comment.
Something went wrong with that request. Please try again.