Skip to content

Commit

Permalink
Revert "Prefix Internet Explorer's accepted mime types with sensible …
Browse files Browse the repository at this point in the history
…defaults."

IE XHR requests are misinterpreted as HTML instead of JS.

This reverts commit c680f23.
  • Loading branch information
josh committed Nov 23, 2009
1 parent 0bc150c commit 0f0f977
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 49 deletions.
15 changes: 3 additions & 12 deletions actionpack/lib/action_controller/request.rb
Expand Up @@ -99,25 +99,15 @@ def media_type
content_type.to_s
end

# Regular expression to match the Internet Explorer user agent string.
INTERNET_EXPLORER = /MSIE\s[\d\.]+;/

# Returns true if the user agent is Internet Explorer.
def internet_explorer?
user_agent =~ INTERNET_EXPLORER
end

# Returns the accepted MIME types for the request.
# Returns the accepted MIME type for the request.
def accepts
@accepts ||= begin
header = @env['HTTP_ACCEPT'].to_s.strip

if header.empty?
[content_type, Mime::ALL].compact
else
accepts = Mime::Type.parse(header)
accepts.unshift(Mime::HTML, Mime::XML) if internet_explorer?
accepts
Mime::Type.parse(header)
end
end
end
Expand Down Expand Up @@ -174,6 +164,7 @@ def format
end
end


# Sets the \format by string extension, which can be used to force custom formats
# that are not controlled by the extension.
#
Expand Down
37 changes: 0 additions & 37 deletions actionpack/test/controller/request_test.rb
Expand Up @@ -371,43 +371,6 @@ def test_content_type_with_charset
assert_equal Mime::XML, request.content_type
end

def test_internet_explorer_user_agent_check
assert([
"curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3",
"Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00",
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9",
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.23) Gecko/20090815 Camino/1.6.9 (like Firefox/2.0.0.23)",
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5"
].all? do |user_agent|
!stub_request('HTTP_USER_AGENT' => user_agent).internet_explorer?
end)

assert([
"Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; )",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Win64; x64; Trident/4.0)"
].all? do |user_agent|
stub_request('HTTP_USER_AGENT' => user_agent).internet_explorer?
end)
end

def test_accepts_without_user_agent
request = stub_request 'HTTP_ACCEPT' => 'text/html, text/csv, */*'
assert_equal [Mime::HTML, Mime::CSV, Mime::ALL], request.accepts
end

def test_accepts_for_regular_user_agent
request = stub_request 'HTTP_USER_AGENT' => "curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3", 'HTTP_ACCEPT' => 'text/html, text/csv, */*'
assert_equal [Mime::HTML, Mime::CSV, Mime::ALL], request.accepts
end

def test_accepts_for_internet_explorer
request = stub_request 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Win64; x64)',
'HTTP_ACCEPT' => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, application/x-silverlight, */*"
assert_equal 16, request.accepts.length
assert_equal [Mime::HTML, Mime::XML], request.accepts[0..1]
end

def test_user_agent
request = stub_request 'HTTP_USER_AGENT' => 'TestAgent'
assert_equal 'TestAgent', request.user_agent
Expand Down

1 comment on commit 0f0f977

@voxxit
Copy link
Contributor

@voxxit voxxit commented on 0f0f977 Nov 30, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we reverting this again? It's a pretty silly problem in IE currently.

Please sign in to comment.