From 2a03e42f2a341340bbe2b4ee1c0ffd53fac04fb5 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 6 Nov 2020 03:42:07 +0000 Subject: [PATCH] Update deep_munge patch to rails 4.1 where the code is now in ActionDispatch::Request::Utils --- lib/action_dispatch/request.rb | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/action_dispatch/request.rb b/lib/action_dispatch/request.rb index a0f26ecd01..66f1b1c763 100644 --- a/lib/action_dispatch/request.rb +++ b/lib/action_dispatch/request.rb @@ -28,22 +28,38 @@ # https://gist.github.com/victorblasco/f675b4cbaf9c0bc19f81 module ActionDispatch - class Request - def deep_munge(hash) - hash.each do |_k, v| - case v - when Array - v.grep(Hash) { |x| deep_munge(x) } - v.compact! + class Request < Rack::Request + class Utils # :nodoc: - # This patch removes the next line - # hash[k] = nil if v.empty? - when Hash - deep_munge(v) + 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! + + # This patch removes the following lines + #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 - - hash end end end