From 84e8accd6fb83031e4c27e44925d7596655285f7 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Thu, 3 Dec 2015 15:19:25 -0300 Subject: Do not add format key to request_params I did this change but it is affecting how the request params end up after being processed by the router. To be in the safe side, I just take the format from the extension in the URL when is not present in those params and it's being used only for the `Request#formats` method --- .../lib/action_dispatch/http/mime_negotiation.rb | 9 +++++++++ actionpack/lib/action_dispatch/http/parameters.rb | 19 ++----------------- actionpack/test/dispatch/routing_test.rb | 1 - 3 files changed, 11 insertions(+), 18 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index 7acf91902d..004713ec1a 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -67,6 +67,8 @@ module ActionDispatch v = if params_readable Array(Mime[parameters[:format]]) + elsif format_from_path_extension + [Mime[format_from_path_extension]] elsif use_accept_header && valid_accept_header accepts elsif xhr? @@ -160,6 +162,13 @@ module ActionDispatch def use_accept_header !self.class.ignore_accept_header end + + def format_from_path_extension + path = @env['action_dispatch.original_path'] || @env['PATH_INFO'] + if match = path && path.match(/\.(\w+)\z/) + match.captures.first + end + end end end end diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 9d450beae5..c9df787351 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -41,9 +41,9 @@ module ActionDispatch # Returns a hash with the \parameters used to form the \path of the request. # Returned hash keys are strings: # - # {'action' => 'my_action', 'controller' => 'my_controller', format => 'html'} + # {'action' => 'my_action', 'controller' => 'my_controller'} def path_parameters - get_header(PARAMETERS_KEY) || default_path_parameters + get_header(PARAMETERS_KEY) || {} end private @@ -66,21 +66,6 @@ module ActionDispatch def params_parsers ActionDispatch::Request.parameter_parsers end - - def default_path_parameters - if format = format_from_path_extension - { format: format } - else - {} - end - end - - def format_from_path_extension - path = @env['action_dispatch.original_path'] || @env['PATH_INFO'] - if match = path && path.match(/\.(\w+)\z/) - match.captures.first - end - end end end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 1b711e1bf8..8972f3e74d 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3272,7 +3272,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest expected_params = { controller: 'downloads', action: 'show', - format: 'tar', id: '1' } -- cgit v1.2.3