aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-05 12:17:30 -0800
committerJosé Valim <jose.valim@gmail.com>2012-03-05 12:17:30 -0800
commitdc8071520761d954d0958316a45aa9223b70a3d1 (patch)
treecd9ac2838a6da9671a7ed3fb3496c906f98ae4e1 /actionpack
parentc84d3276def77889fa7b5833ebc51919b349c6ae (diff)
parent8c4b3a4dea79e949da583b379714a2cc4bf92ab4 (diff)
downloadrails-dc8071520761d954d0958316a45aa9223b70a3d1.tar.gz
rails-dc8071520761d954d0958316a45aa9223b70a3d1.tar.bz2
rails-dc8071520761d954d0958316a45aa9223b70a3d1.zip
Merge pull request #5290 from steveklabnik/master
Added parsing of arbitrary media type parameters.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb6
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb6
2 files changed, 9 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 2152351703..e039eb1288 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -82,7 +82,7 @@ module Mime
class << self
TRAILING_STAR_REGEXP = /(text|application)\/\*/
- Q_SEPARATOR_REGEXP = /;\s*q=/
+ PARAMETER_SEPARATOR_REGEXP = /;\s*\w+="?\w+"?/
def lookup(string)
LOOKUP[string]
@@ -109,7 +109,7 @@ module Mime
def parse(accept_header)
if accept_header !~ /,/
- accept_header = accept_header.split(Q_SEPARATOR_REGEXP).first
+ accept_header = accept_header.split(PARAMETER_SEPARATOR_REGEXP).first
if accept_header =~ TRAILING_STAR_REGEXP
parse_data_with_trailing_star($1)
else
@@ -119,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(Q_SEPARATOR_REGEXP)
+ params, q = header.split(PARAMETER_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 0372c42920..e3f9faaa64 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -75,6 +75,12 @@ class MimeTypeTest < ActiveSupport::TestCase
assert_equal expect, Mime::Type.parse(accept)
end
+ test "parse arbitarry media type parameters" do
+ accept = 'multipart/form-data; boundary="simple boundary"'
+ expect = [Mime::MULTIPART_FORM]
+ 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"