Skip to content

Commit 81b2fb6

Browse files
Merge pull request rails#38413 from nahi/space_before_mime_type_parameter
allow parameter delimiter without space
2 parents db60199 + 6937ecf commit 81b2fb6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

actionpack/lib/action_dispatch/http/mime_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def unregister(symbol)
228228
MIME_NAME = "[a-zA-Z0-9][a-zA-Z0-9#{Regexp.escape('!#$&-^_.+')}]{0,126}"
229229
MIME_PARAMETER_KEY = "[a-zA-Z0-9][a-zA-Z0-9#{Regexp.escape('!#$&-^_.+')}]{0,126}"
230230
MIME_PARAMETER_VALUE = "#{Regexp.escape('"')}?[a-zA-Z0-9][a-zA-Z0-9#{Regexp.escape('!#$&-^_.+')}]{0,126}#{Regexp.escape('"')}?"
231-
MIME_PARAMETER = "\s*\;\s+#{MIME_PARAMETER_KEY}(?:\=#{MIME_PARAMETER_VALUE})?"
231+
MIME_PARAMETER = "\s*\;\s*#{MIME_PARAMETER_KEY}(?:\=#{MIME_PARAMETER_VALUE})?"
232232
MIME_REGEXP = /\A(?:\*\/\*|#{MIME_NAME}\/(?:\*|#{MIME_NAME})(?:\s*#{MIME_PARAMETER}\s*)*)\z/
233233

234234
class InvalidMimeType < StandardError; end

actionpack/test/dispatch/mime_type_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ class MimeTypeTest < ActiveSupport::TestCase
194194
assert_equal 'text/html; parameter=abc; parameter2="xyz"', Mime::Type.new('text/html; parameter=abc; parameter2="xyz"').to_s
195195
end
196196

197+
test "can be initialized with parameters without having space after ;" do
198+
assert_equal "text/html;parameter", Mime::Type.new("text/html;parameter").to_s
199+
assert_equal 'text/html;parameter=abc;parameter2="xyz"', Mime::Type.new('text/html;parameter=abc;parameter2="xyz"').to_s
200+
end
201+
197202
test "invalid mime types raise error" do
198203
assert_raises Mime::Type::InvalidMimeType do
199204
Mime::Type.new("too/many/slash")

0 commit comments

Comments
 (0)