Browse files

Merge pull request #9541 from maximerety/fix_7774

Fix formats on xhr requests when HTTP_ACCEPT is empty string
  • Loading branch information...
2 parents 9025f49 + 1d217ab commit b359c5db9f0e7dfb2cbf34362a9b310cf5aadd3a @josevalim josevalim committed Mar 4, 2013
View
2 actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -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
View
5 actionpack/test/dispatch/request_test.rb
@@ -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 b359c5d

Please sign in to comment.