1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rely on default Mime format when MimeNegotiation#format_from_path_extension is not a valid type

Closes #22747
This commit is contained in:
Jorge Bejar 2015-12-29 11:39:58 -03:00
parent 929c61573e
commit 9a85da9367
2 changed files with 15 additions and 3 deletions

View file

@ -67,8 +67,8 @@ module ActionDispatch
v = if params_readable
Array(Mime[parameters[:format]])
elsif format = format_from_path_extension
Array(Mime[format])
elsif extension_format = format_from_path_extension
[extension_format]
elsif use_accept_header && valid_accept_header
accepts
elsif xhr?
@ -166,7 +166,7 @@ module ActionDispatch
def format_from_path_extension
path = @env['action_dispatch.original_path'] || @env['PATH_INFO']
if match = path && path.match(/\.(\w+)\z/)
match.captures.first
Mime[match.captures.first]
end
end
end

View file

@ -897,6 +897,18 @@ class RequestFormat < BaseRequestTest
ActionDispatch::Request.ignore_accept_header = old_ignore_accept_header
end
end
test "format taken from the path extension" do
request = stub_request 'PATH_INFO' => '/foo.xml'
assert_called(request, :parameters, times: 1, returns: {}) do
assert_equal [Mime[:xml]], request.formats
end
request = stub_request 'PATH_INFO' => '/foo.123'
assert_called(request, :parameters, times: 1, returns: {}) do
assert_equal [Mime[:html]], request.formats
end
end
end
class RequestMimeType < BaseRequestTest