提交 84e8accd 编写于 作者: J Jorge Bejar

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
上级 fa092512
......@@ -67,6 +67,8 @@ def formats
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 @@ def valid_accept_header
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
......@@ -41,9 +41,9 @@ def path_parameters=(parameters) #:nodoc:
# 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 @@ def parse_formatted_parameters(parsers)
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
......@@ -3272,7 +3272,6 @@ def test_multiple_positional_args_with_the_same_name
expected_params = {
controller: 'downloads',
action: 'show',
format: 'tar',
id: '1'
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册