aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2013-03-04 07:26:17 -0800
committerJosé Valim <jose.valim@plataformatec.com.br>2013-03-04 07:26:17 -0800
commitb359c5db9f0e7dfb2cbf34362a9b310cf5aadd3a (patch)
treedeb5f024cc389a29b5371460e636f1832d61dd74 /actionpack
parent9025f495700fb67cf661ed79ac8c3b0912c13d4c (diff)
parent1d217abc3db4d229686525fd7fa448ebd5746cad (diff)
downloadrails-b359c5db9f0e7dfb2cbf34362a9b310cf5aadd3a.tar.gz
rails-b359c5db9f0e7dfb2cbf34362a9b310cf5aadd3a.tar.bz2
rails-b359c5db9f0e7dfb2cbf34362a9b310cf5aadd3a.zip
Merge pull request #9541 from maximerety/fix_7774
Fix formats on xhr requests when HTTP_ACCEPT is empty string
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_negotiation.rb2
-rw-r--r--actionpack/test/dispatch/request_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb
index 89a7b12818..40bb060d52 100644
--- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb
+++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -121,7 +121,7 @@ module ActionDispatch
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
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 91810864d5..f6de9748ca 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -594,6 +594,11 @@ class RequestTest < ActiveSupport::TestCase
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({})