Skip to content

Commit 52cf1a7

Browse files
committed
rm deep_munge. You will live on in our hearts (and git history)
Now that we have encoding strategies, we can just walk the params hash once to encode as HWIA, and remove nils.
1 parent 3f29929 commit 52cf1a7

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

actionpack/lib/action_dispatch/http/request.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ def session_options=(options)
290290

291291
# Override Rack's GET method to support indifferent access
292292
def GET
293-
@env["action_dispatch.request.query_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {}))
293+
@env["action_dispatch.request.query_parameters"] ||= normalize_encode_params(super || {})
294294
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
295295
raise ActionController::BadRequest.new(:query, e)
296296
end
297297
alias :query_parameters :GET
298298

299299
# Override Rack's POST method to support indifferent access
300300
def POST
301-
@env["action_dispatch.request.request_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {}))
301+
@env["action_dispatch.request.request_parameters"] ||= normalize_encode_params(super || {})
302302
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
303303
raise ActionController::BadRequest.new(:request, e)
304304
end
@@ -318,11 +318,6 @@ def local?
318318
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
319319
end
320320

321-
protected
322-
def parse_query(*)
323-
Utils.deep_munge(super)
324-
end
325-
326321
private
327322
def check_method(name)
328323
HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS[0...-1].join(', ')}, and #{HTTP_METHODS[-1]}")

actionpack/lib/action_dispatch/middleware/params_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(message, original_exception)
1717
Mime::JSON => lambda { |raw_post|
1818
data = ActiveSupport::JSON.decode(raw_post)
1919
data = {:_json => data} unless data.is_a?(Hash)
20-
Request::Utils.deep_munge(data).with_indifferent_access
20+
Request::Utils.normalize_encode_params(data)
2121
}
2222
}
2323

actionpack/lib/action_dispatch/request/utils.rb

+12-18
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ class Utils # :nodoc:
66
self.perform_deep_munge = true
77

88
def self.normalize_encode_params(params)
9-
ParamEncoder.normalize_encode_params params
9+
if perform_deep_munge
10+
NoNilParamEncoder.normalize_encode_params params
11+
else
12+
ParamEncoder.normalize_encode_params params
13+
end
1014
end
1115

12-
class ParamEncoder
16+
class ParamEncoder # :nodoc:
1317
# Convert nested Hash to HashWithIndifferentAccess.
1418
#
1519
def self.normalize_encode_params(params)
@@ -34,22 +38,12 @@ def self.handle_array(params)
3438
end
3539
end
3640

37-
class << self
38-
# Remove nils from the params hash
39-
def deep_munge(hash)
40-
return hash unless perform_deep_munge
41-
42-
hash.each do |k, v|
43-
case v
44-
when Array
45-
v.grep(Hash) { |x| deep_munge(x) }
46-
v.compact!
47-
when Hash
48-
deep_munge(v)
49-
end
50-
end
51-
52-
hash
41+
# Remove nils from the params hash
42+
class NoNilParamEncoder < ParamEncoder # :nodoc:
43+
def self.handle_array(params)
44+
list = super
45+
list.compact!
46+
list
5347
end
5448
end
5549
end

0 commit comments

Comments
 (0)