diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-02-22 21:39:44 -0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-02-22 21:39:44 -0300 |
commit | e7299497871e20c3a28516a4e84fe1789c8795a8 (patch) | |
tree | c60aec696d0e74ffe0f0efbc8a2a17c8280f473e /actionpack/lib/action_dispatch | |
parent | 7a36686c115f1c6c60ac0a51bc4991c3d32b6e5d (diff) | |
parent | 4f30df4b524b5da22491090e22f5c2de789dd016 (diff) | |
download | rails-e7299497871e20c3a28516a4e84fe1789c8795a8.tar.gz rails-e7299497871e20c3a28516a4e84fe1789c8795a8.tar.bz2 rails-e7299497871e20c3a28516a4e84fe1789c8795a8.zip |
Merge pull request #23816 from rails/params_parser_api
Make sure the parameter parsers register API work with overidden mime types.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/parameters.rb | 21 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 1 |
2 files changed, 16 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index cca7376ffa..ff5031d7d5 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -1,22 +1,31 @@ module ActionDispatch module Http module Parameters + extend ActiveSupport::Concern + PARAMETERS_KEY = 'action_dispatch.request.path_parameters' DEFAULT_PARSERS = { - Mime[:json] => lambda { |raw_post| + Mime[:json].symbol => -> (raw_post) { data = ActiveSupport::JSON.decode(raw_post) data.is_a?(Hash) ? data : {:_json => data} } } - def self.included(klass) - class << klass - attr_accessor :parameter_parsers + included do + class << self + attr_reader :parameter_parsers end - klass.parameter_parsers = DEFAULT_PARSERS + self.parameter_parsers = DEFAULT_PARSERS end + + module ClassMethods + def parameter_parsers=(parsers) # :nodoc: + @parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key } + end + end + # Returns both GET and POST \parameters in a single hash. def parameters params = get_header("action_dispatch.request.parameters") @@ -51,7 +60,7 @@ module ActionDispatch def parse_formatted_parameters(parsers) return yield if content_length.zero? - strategy = parsers.fetch(content_mime_type) { return yield } + strategy = parsers.fetch(content_mime_type.symbol) { return yield } begin strategy.call(raw_post) diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index c2a4f46e67..5841c978af 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -37,6 +37,7 @@ module ActionDispatch # The +parsers+ argument can take Hash of parsers where key is identifying # content mime type, and value is a lambda that is going to process data. def self.new(app, parsers = {}) + parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key } ActionDispatch::Request.parameter_parsers = ActionDispatch::Request::DEFAULT_PARSERS.merge(parsers) app end |