Permalink
Browse files

Fix formats on xhr requests when HTTP_ACCEPT is empty string

Fix ActionDispatch::Request#formats on xhr requests when HTTP_ACCEPT
header is empty string. About issue #7774, same fix as in commit bebb02f
but for xhr requests.
  • Loading branch information...
1 parent 2e28045 commit 1d217abc3db4d229686525fd7fa448ebd5746cad @maximerety committed Mar 4, 2013
@@ -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
@@ -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({})

0 comments on commit 1d217ab

Please sign in to comment.