提交 269424b0 编写于 作者: X Xavier Noria

refactors AC::Parameters#fetch

AC::Parameters#fetch was refactored in 7171111d 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.
上级 e219bf0e
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册