aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-30 12:21:17 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-30 12:21:17 -0700
commit47f4d8d513ed5bb4516cd1175889fcabfb361263 (patch)
treeebeb5de3e7f00f24f3d2557f13f18b8fbe136842 /actionpack
parent87f3eb61c641610f758e27c6c25c92b637ad3041 (diff)
parent5438f6866efa679331e5c998ecbc5948e80cd503 (diff)
downloadrails-47f4d8d513ed5bb4516cd1175889fcabfb361263.tar.gz
rails-47f4d8d513ed5bb4516cd1175889fcabfb361263.tar.bz2
rails-47f4d8d513ed5bb4516cd1175889fcabfb361263.zip
Merge pull request #10803 from gsamokovarov/extract-deep-munge
Extract ActionDispatch::Request#deep_munge
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb19
-rw-r--r--actionpack/lib/action_dispatch/middleware/params_parser.rb2
-rw-r--r--actionpack/lib/action_dispatch/request/utils.rb24
3 files changed, 27 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index ebd87c40b5..4ca1d35489 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -22,6 +22,7 @@ module ActionDispatch
include ActionDispatch::Http::URL
autoload :Session, 'action_dispatch/request/session'
+ autoload :Utils, 'action_dispatch/request/utils'
LOCALHOST = Regexp.union [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/]
@@ -299,26 +300,10 @@ module ActionDispatch
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
end
- # Remove nils from the params hash
- def deep_munge(hash)
- hash.each do |k, v|
- case v
- when Array
- v.grep(Hash) { |x| deep_munge(x) }
- v.compact!
- hash[k] = nil if v.empty?
- when Hash
- deep_munge(v)
- end
- end
-
- hash
- end
-
protected
def parse_query(qs)
- deep_munge(super)
+ Utils.deep_munge(super)
end
private
diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb
index 0fa1e9b859..fb70b60ef6 100644
--- a/actionpack/lib/action_dispatch/middleware/params_parser.rb
+++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -43,7 +43,7 @@ module ActionDispatch
when :json
data = ActiveSupport::JSON.decode(request.body)
data = {:_json => data} unless data.is_a?(Hash)
- request.deep_munge(data).with_indifferent_access
+ Request::Utils.deep_munge(data).with_indifferent_access
else
false
end
diff --git a/actionpack/lib/action_dispatch/request/utils.rb b/actionpack/lib/action_dispatch/request/utils.rb
new file mode 100644
index 0000000000..8b43cdada8
--- /dev/null
+++ b/actionpack/lib/action_dispatch/request/utils.rb
@@ -0,0 +1,24 @@
+module ActionDispatch
+ class Request < Rack::Request
+ class Utils # :nodoc:
+ class << self
+ # Remove nils from the params hash
+ def deep_munge(hash)
+ hash.each do |k, v|
+ case v
+ when Array
+ v.grep(Hash) { |x| deep_munge(x) }
+ v.compact!
+ hash[k] = nil if v.empty?
+ when Hash
+ deep_munge(v)
+ end
+ end
+
+ hash
+ end
+ end
+ end
+ end
+end
+