mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
push param encoding in to the utils module
we'll refactor deep munge mostly out of existence shortly
This commit is contained in:
parent
f620d6c25e
commit
3f299296d1
2 changed files with 30 additions and 14 deletions
|
@ -37,20 +37,7 @@ module ActionDispatch
|
|||
# Convert nested Hash to HashWithIndifferentAccess.
|
||||
#
|
||||
def normalize_encode_params(params)
|
||||
case params
|
||||
when Array
|
||||
params.map! { |el| normalize_encode_params(el) }
|
||||
when Hash
|
||||
if params.has_key?(:tempfile)
|
||||
UploadedFile.new(params)
|
||||
else
|
||||
params.each_with_object({}) do |(key, val), new_hash|
|
||||
new_hash[key] = normalize_encode_params(val)
|
||||
end.with_indifferent_access
|
||||
end
|
||||
else
|
||||
params
|
||||
end
|
||||
ActionDispatch::Request::Utils.normalize_encode_params params
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,35 @@ module ActionDispatch
|
|||
mattr_accessor :perform_deep_munge
|
||||
self.perform_deep_munge = true
|
||||
|
||||
def self.normalize_encode_params(params)
|
||||
ParamEncoder.normalize_encode_params params
|
||||
end
|
||||
|
||||
class ParamEncoder
|
||||
# Convert nested Hash to HashWithIndifferentAccess.
|
||||
#
|
||||
def self.normalize_encode_params(params)
|
||||
case params
|
||||
when Array
|
||||
handle_array params
|
||||
when Hash
|
||||
if params.has_key?(:tempfile)
|
||||
ActionDispatch::Http::UploadedFile.new(params)
|
||||
else
|
||||
params.each_with_object({}) do |(key, val), new_hash|
|
||||
new_hash[key] = normalize_encode_params(val)
|
||||
end.with_indifferent_access
|
||||
end
|
||||
else
|
||||
params
|
||||
end
|
||||
end
|
||||
|
||||
def self.handle_array(params)
|
||||
params.map! { |el| normalize_encode_params(el) }
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
# Remove nils from the params hash
|
||||
def deep_munge(hash)
|
||||
|
|
Loading…
Reference in a new issue