mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
3f299296d1
commit
52cf1a71b3
3 changed files with 15 additions and 26 deletions
|
@ -290,7 +290,7 @@ module ActionDispatch
|
|||
|
||||
# Override Rack's GET method to support indifferent access
|
||||
def GET
|
||||
@env["action_dispatch.request.query_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {}))
|
||||
@env["action_dispatch.request.query_parameters"] ||= normalize_encode_params(super || {})
|
||||
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
|
||||
raise ActionController::BadRequest.new(:query, e)
|
||||
end
|
||||
|
@ -298,7 +298,7 @@ module ActionDispatch
|
|||
|
||||
# Override Rack's POST method to support indifferent access
|
||||
def POST
|
||||
@env["action_dispatch.request.request_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {}))
|
||||
@env["action_dispatch.request.request_parameters"] ||= normalize_encode_params(super || {})
|
||||
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
|
||||
raise ActionController::BadRequest.new(:request, e)
|
||||
end
|
||||
|
@ -318,11 +318,6 @@ module ActionDispatch
|
|||
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
|
||||
end
|
||||
|
||||
protected
|
||||
def parse_query(*)
|
||||
Utils.deep_munge(super)
|
||||
end
|
||||
|
||||
private
|
||||
def check_method(name)
|
||||
HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS[0...-1].join(', ')}, and #{HTTP_METHODS[-1]}")
|
||||
|
|
|
@ -17,7 +17,7 @@ module ActionDispatch
|
|||
Mime::JSON => lambda { |raw_post|
|
||||
data = ActiveSupport::JSON.decode(raw_post)
|
||||
data = {:_json => data} unless data.is_a?(Hash)
|
||||
Request::Utils.deep_munge(data).with_indifferent_access
|
||||
Request::Utils.normalize_encode_params(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,14 @@ module ActionDispatch
|
|||
self.perform_deep_munge = true
|
||||
|
||||
def self.normalize_encode_params(params)
|
||||
ParamEncoder.normalize_encode_params params
|
||||
if perform_deep_munge
|
||||
NoNilParamEncoder.normalize_encode_params params
|
||||
else
|
||||
ParamEncoder.normalize_encode_params params
|
||||
end
|
||||
end
|
||||
|
||||
class ParamEncoder
|
||||
class ParamEncoder # :nodoc:
|
||||
# Convert nested Hash to HashWithIndifferentAccess.
|
||||
#
|
||||
def self.normalize_encode_params(params)
|
||||
|
@ -34,22 +38,12 @@ module ActionDispatch
|
|||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
# Remove nils from the params hash
|
||||
def deep_munge(hash)
|
||||
return hash unless perform_deep_munge
|
||||
|
||||
hash.each do |k, v|
|
||||
case v
|
||||
when Array
|
||||
v.grep(Hash) { |x| deep_munge(x) }
|
||||
v.compact!
|
||||
when Hash
|
||||
deep_munge(v)
|
||||
end
|
||||
end
|
||||
|
||||
hash
|
||||
# Remove nils from the params hash
|
||||
class NoNilParamEncoder < ParamEncoder # :nodoc:
|
||||
def self.handle_array(params)
|
||||
list = super
|
||||
list.compact!
|
||||
list
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue