aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-02-07 08:28:06 -0800
committerJosé Valim <jose.valim@plataformatec.com.br>2012-02-07 08:28:06 -0800
commitdd9b428cbcb6453e01f25a35479a5ab5e19c03fc (patch)
tree449032229f700a5ab52d5fd9ec35c862f06e972a
parented9aeec92d60c2b62f3cef6b02112ad4401a0bcc (diff)
parent3b203f7cb6c54963f74d1ab4237bf7403cc3bf8f (diff)
downloadrails-dd9b428cbcb6453e01f25a35479a5ab5e19c03fc.tar.gz
rails-dd9b428cbcb6453e01f25a35479a5ab5e19c03fc.tar.bz2
rails-dd9b428cbcb6453e01f25a35479a5ab5e19c03fc.zip
Merge pull request #4918 from scottwb/fix-single-accept-with-q
Fix MIME::Type.parse handling of single media with a q value
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb4
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb6
2 files changed, 9 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 25affb9f50..2152351703 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -82,6 +82,7 @@ module Mime
class << self
TRAILING_STAR_REGEXP = /(text|application)\/\*/
+ Q_SEPARATOR_REGEXP = /;\s*q=/
def lookup(string)
LOOKUP[string]
@@ -108,6 +109,7 @@ module Mime
def parse(accept_header)
if accept_header !~ /,/
+ accept_header = accept_header.split(Q_SEPARATOR_REGEXP).first
if accept_header =~ TRAILING_STAR_REGEXP
parse_data_with_trailing_star($1)
else
@@ -117,7 +119,7 @@ module Mime
# keep track of creation order to keep the subsequent sort stable
list, index = [], 0
accept_header.split(/,/).each do |header|
- params, q = header.split(/;\s*q=/)
+ params, q = header.split(Q_SEPARATOR_REGEXP)
if params.present?
params.strip!
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index db21080c42..0372c42920 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -69,6 +69,12 @@ class MimeTypeTest < ActiveSupport::TestCase
assert_equal expect, Mime::Type.parse(accept)
end
+ test "parse single media range with q" do
+ accept = "text/html;q=0.9"
+ expect = [Mime::HTML]
+ 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"