aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/request/utils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch/request/utils.rb')
-rw-r--r--actionpack/lib/action_dispatch/request/utils.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/request/utils.rb b/actionpack/lib/action_dispatch/request/utils.rb
new file mode 100644
index 0000000000..9d4f1aa3c5
--- /dev/null
+++ b/actionpack/lib/action_dispatch/request/utils.rb
@@ -0,0 +1,35 @@
+module ActionDispatch
+ class Request < Rack::Request
+ class Utils # :nodoc:
+
+ mattr_accessor :perform_deep_munge
+ self.perform_deep_munge = true
+
+ class << self
+ # Remove nils from the params hash
+ def deep_munge(hash, keys = [])
+ return hash unless perform_deep_munge
+
+ hash.each do |k, v|
+ keys << k
+ case v
+ when Array
+ v.grep(Hash) { |x| deep_munge(x, keys) }
+ v.compact!
+ if v.empty?
+ hash[k] = nil
+ ActiveSupport::Notifications.instrument("deep_munge.action_controller", keys: keys)
+ end
+ when Hash
+ deep_munge(v, keys)
+ end
+ keys.pop
+ end
+
+ hash
+ end
+ end
+ end
+ end
+end
+