Created
May 14, 2011 02:33
-
-
Save AquaGeek/971715 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #5833
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a4cb744ef1ce15a18a9a60608d2e01a30d2d000b Mon Sep 17 00:00:00 2001 | |
From: Joel Chippindale <joel@joelchippindale.com> | |
Date: Mon, 18 Oct 2010 12:04:54 +0100 | |
Subject: [PATCH] Fix Mime::Type#parse for single media range with accepts params [#5833 state:resolved] | |
--- | |
actionpack/lib/action_controller/mime_type.rb | 8 ++++---- | |
actionpack/test/controller/mime_type_test.rb | 8 +++++++- | |
2 files changed, 11 insertions(+), 5 deletions(-) | |
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb | |
index 017626b..c5fda94 100644 | |
--- a/actionpack/lib/action_controller/mime_type.rb | |
+++ b/actionpack/lib/action_controller/mime_type.rb | |
@@ -87,14 +87,14 @@ module Mime | |
def parse(accept_header) | |
if accept_header !~ /,/ | |
- [Mime::Type.lookup(accept_header)] | |
+ [Mime::Type.lookup(accept_header.split(';').first)] | |
else | |
# keep track of creation order to keep the subsequent sort stable | |
list = [] | |
- accept_header.split(/,/).each_with_index do |header, index| | |
- params, q = header.split(/;\s*q=/) | |
+ accept_header.split(/,/).each_with_index do |header, index| | |
+ params, q = header.split(/;\s*q=/) | |
if params | |
- params.strip! | |
+ params.strip! | |
list << AcceptItem.new(index, params, q) unless params.empty? | |
end | |
end | |
diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb | |
index c7faa62..aa1a4a5 100644 | |
--- a/actionpack/test/controller/mime_type_test.rb | |
+++ b/actionpack/test/controller/mime_type_test.rb | |
@@ -19,9 +19,15 @@ class MimeTypeTest < Test::Unit::TestCase | |
def test_parse_with_q | |
accept = "text/xml,application/xhtml+xml,text/yaml; q=0.3,application/xml,text/html; q=0.8,image/png,text/plain; q=0.5,application/pdf,*/*; q=0.2" | |
expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PDF, Mime::TEXT, Mime::YAML, Mime::ALL] | |
+ end | |
+ | |
+ # Accept header (which is valid even if it is pointless) send with user HTTP_USER_AGENT: searchdnabot/Nutch-1.0 | |
+ def test_parse_single_with_q | |
+ accept = "*/*;q=0.1" | |
+ expect = [Mime::ALL] | |
assert_equal expect, Mime::Type.parse(accept) | |
end | |
- | |
+ | |
# Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) | |
def test_parse_crappy_broken_acceptlines | |
accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5" | |
-- | |
1.7.3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 90f1d68ae8a62980613b9fc2e17d6da5809957fa Mon Sep 17 00:00:00 2001 | |
From: Joel Chippindale <joel.chippindale@econsultancy.com> | |
Date: Mon, 7 Feb 2011 12:55:42 +0000 | |
Subject: [PATCH] [PATCH] Fix Mime::Type#parse for single media range with accepts params [#5833 state:resolved] | |
--- | |
actionpack/lib/action_dispatch/http/mime_type.rb | 2 +- | |
actionpack/test/dispatch/mime_type_test.rb | 7 +++++++ | |
2 files changed, 8 insertions(+), 1 deletions(-) | |
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb | |
index 5b87a80..06dd523 100644 | |
--- a/actionpack/lib/action_dispatch/http/mime_type.rb | |
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb | |
@@ -111,7 +111,7 @@ module Mime | |
if accept_header =~ TRAILING_STAR_REGEXP | |
parse_data_with_trailing_star($1) | |
else | |
- [Mime::Type.lookup(accept_header)] | |
+ [Mime::Type.lookup(accept_header.split(';').first)] | |
end | |
else | |
# keep track of creation order to keep the subsequent sort stable | |
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb | |
index 9782f32..a824f1c 100644 | |
--- a/actionpack/test/dispatch/mime_type_test.rb | |
+++ b/actionpack/test/dispatch/mime_type_test.rb | |
@@ -69,6 +69,13 @@ class MimeTypeTest < ActiveSupport::TestCase | |
assert_equal expect, Mime::Type.parse(accept) | |
end | |
+ # Accept header (which is valid even if it is pointless) send with user HTTP_USER_AGENT: searchdnabot/Nutch-1.0 | |
+ test "parse single with q" do | |
+ accept = "*/*;q=0.1" | |
+ expect = [Mime::ALL] | |
+ assert_equal expect, Mime::Type.parse(accept) | |
+ end | |
+ | |
# Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) | |
test "parse broken acceptlines" do | |
accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5" | |
-- | |
1.7.3 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 35229862e42e17be8b27766fa15677175142c061 Mon Sep 17 00:00:00 2001 | |
From: Joel Chippindale <joel@joelchippindale.com> | |
Date: Mon, 18 Oct 2010 11:55:55 +0100 | |
Subject: [PATCH] Fix Mime::Type#parse for single media range with accepts params [#5833 state:resolved] | |
--- | |
actionpack/lib/action_dispatch/http/mime_type.rb | 2 +- | |
actionpack/test/dispatch/mime_type_test.rb | 7 +++++++ | |
2 files changed, 8 insertions(+), 1 deletions(-) | |
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb | |
index 8f1c9b6..5b5dfa8 100644 | |
--- a/actionpack/lib/action_dispatch/http/mime_type.rb | |
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb | |
@@ -105,7 +105,7 @@ module Mime | |
def parse(accept_header) | |
if accept_header !~ /,/ | |
- [Mime::Type.lookup(accept_header)] | |
+ [Mime::Type.lookup(accept_header.split(';').first)] | |
else | |
# keep track of creation order to keep the subsequent sort stable | |
list = [] | |
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb | |
index 4c2b955..2670c51 100644 | |
--- a/actionpack/test/dispatch/mime_type_test.rb | |
+++ b/actionpack/test/dispatch/mime_type_test.rb | |
@@ -22,6 +22,13 @@ class MimeTypeTest < ActiveSupport::TestCase | |
assert_equal expect, Mime::Type.parse(accept) | |
end | |
+ # Accept header (which is valid even if it is pointless) send with user HTTP_USER_AGENT: searchdnabot/Nutch-1.0 | |
+ def test_parse_single_with_q | |
+ accept = "*/*;q=0.1" | |
+ expect = [Mime::ALL] | |
+ assert_equal expect, Mime::Type.parse(accept) | |
+ end | |
+ | |
# Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) | |
test "parse broken acceptlines" do | |
accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5" | |
-- | |
1.7.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment