Skip to content

Commit

Permalink
Merge pull request #9541 from maximerety/fix_7774
Browse files Browse the repository at this point in the history
Fix formats on xhr requests when HTTP_ACCEPT is empty string
  • Loading branch information
José Valim committed Mar 4, 2013
2 parents 9025f49 + 1d217ab commit b359c5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_negotiation.rb
Expand Up @@ -121,7 +121,7 @@ def negotiate_mime(order)
BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/

def valid_accept_header
(xhr? && (accept || content_mime_type)) ||
(xhr? && (accept.present? || content_mime_type)) ||
(accept.present? && accept !~ BROWSER_LIKE_ACCEPTS)
end

Expand Down
5 changes: 5 additions & 0 deletions actionpack/test/dispatch/request_test.rb
Expand Up @@ -594,6 +594,11 @@ def url_for(options = {})
request.expects(:parameters).at_least_once.returns({})
assert_equal [Mime::HTML], request.formats

request = stub_request 'HTTP_ACCEPT' => '',
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
request.expects(:parameters).at_least_once.returns({})
assert_equal [Mime::JS], request.formats

request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8',
'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
request.expects(:parameters).at_least_once.returns({})
Expand Down

0 comments on commit b359c5d

Please sign in to comment.