aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-07-21 18:04:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-07-21 18:04:12 -0700
commit3f299296d15bff5735a430b9d2e33476e8f24f69 (patch)
tree8a03d7f90b1d4e3c8b753efdda03156ee289d1bc /actionpack/lib/action_dispatch
parentf620d6c25ef4d971a29e637e1a772cb5b12f2f26 (diff)
downloadrails-3f299296d15bff5735a430b9d2e33476e8f24f69.tar.gz
rails-3f299296d15bff5735a430b9d2e33476e8f24f69.tar.bz2
rails-3f299296d15bff5735a430b9d2e33476e8f24f69.zip
push param encoding in to the utils module
we'll refactor deep munge mostly out of existence shortly
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/parameters.rb15
-rw-r--r--actionpack/lib/action_dispatch/request/utils.rb29
2 files changed, 30 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb
index b3633015b5..4defb7f858 100644
--- a/actionpack/lib/action_dispatch/http/parameters.rb
+++ b/actionpack/lib/action_dispatch/http/parameters.rb
@@ -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
diff --git a/actionpack/lib/action_dispatch/request/utils.rb b/actionpack/lib/action_dispatch/request/utils.rb
index 8836ba6d59..01fd5efd5e 100644
--- a/actionpack/lib/action_dispatch/request/utils.rb
+++ b/actionpack/lib/action_dispatch/request/utils.rb
@@ -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)