Skip to content

Commit a087cf4

Browse files
committed
Transform the mime object to symbol when registering the parsers
This will keep our current API working without having the users to change their codebases.
1 parent 97ed810 commit a087cf4

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

actionpack/lib/action_dispatch/http/parameters.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module ActionDispatch
22
module Http
33
module Parameters
4+
extend ActiveSupport::Concern
5+
46
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
57

68
DEFAULT_PARSERS = {
@@ -10,13 +12,20 @@ module Parameters
1012
}
1113
}
1214

13-
def self.included(klass)
14-
class << klass
15-
attr_accessor :parameter_parsers
15+
included do
16+
class << self
17+
attr_reader :parameter_parsers
1618
end
1719

18-
klass.parameter_parsers = DEFAULT_PARSERS
20+
self.parameter_parsers = DEFAULT_PARSERS
1921
end
22+
23+
module ClassMethods
24+
def parameter_parsers=(parsers) # :nodoc:
25+
@parameter_parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key }
26+
end
27+
end
28+
2029
# Returns both GET and POST \parameters in a single hash.
2130
def parameters
2231
params = get_header("action_dispatch.request.parameters")

actionpack/lib/action_dispatch/middleware/params_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def original_exception
3737
# The +parsers+ argument can take Hash of parsers where key is identifying
3838
# content mime type, and value is a lambda that is going to process data.
3939
def self.new(app, parsers = {})
40+
parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key }
4041
ActionDispatch::Request.parameter_parsers = ActionDispatch::Request::DEFAULT_PARSERS.merge(parsers)
4142
app
4243
end

actionpack/test/controller/webservice_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_put_json
6565

6666
def test_register_and_use_json_simple
6767
with_test_route_set do
68-
with_params_parsers json: Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do
68+
with_params_parsers Mime[:json] => Proc.new { |data| ActiveSupport::JSON.decode(data)['request'].with_indifferent_access } do
6969
post "/",
7070
params: '{"request":{"summary":"content...","title":"JSON"}}',
7171
headers: { 'CONTENT_TYPE' => 'application/json' }

0 commit comments

Comments
 (0)