Skip to content
Browse files

Backport fixes about #7774 to 3-2-stable

Fix ActionDispatch::Request#formats when HTTP_ACCEPT header is an empty
string.
  • Loading branch information...
1 parent 927e649 commit d0f22a99f9f24d07990e02da55ed937c98d41e03 @maximerety maximerety committed Mar 4, 2013
View
5 actionpack/CHANGELOG.md
@@ -1,5 +1,10 @@
## unreleased ##
+* Fix `ActionDispatch::Request#formats` when the Accept request-header is an
+ empty string. Fix #7774 [Backport #8977, #9541]
+
+ *Soylent + Maxime Réty*
+
* Determine the controller#action from only the matched path when using the
shorthand syntax. Previously the complete path was used, which led
to problems with nesting (scopes and namespaces).
View
4 actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -98,8 +98,8 @@ def negotiate_mime(order)
BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/
def valid_accept_header
- (xhr? && (accept || content_mime_type)) ||
- (accept && accept !~ BROWSER_LIKE_ACCEPTS)
+ (xhr? && (accept.present? || content_mime_type)) ||
+ (accept.present? && accept !~ BROWSER_LIKE_ACCEPTS)
end
def use_accept_header
View
9 actionpack/test/dispatch/request_test.rb
@@ -481,6 +481,15 @@ def url_for(options = {})
request.expects(:parameters).at_least_once.returns({})
assert_equal [ Mime::HTML ], request.formats
+ request = stub_request 'HTTP_ACCEPT' => ''
+ 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 d0f22a9

Please sign in to comment.
Something went wrong with that request. Please try again.