diff options
author | Cliff Pruitt <cliff.pruitt@cliffpruitt.com> | 2019-03-19 10:57:55 -0400 |
---|---|---|
committer | Cliff Pruitt <cliff.pruitt@cliffpruitt.com> | 2019-03-19 11:20:40 -0400 |
commit | ab38aa45497a38bc4a97f5eca430d43989f0b124 (patch) | |
tree | b5ed68da29c19df8d42449b812918a54d714b524 /actionpack/test | |
parent | 299573adc60fe0f7aa68f9c66df5ffe2efb0df40 (diff) | |
download | rails-ab38aa45497a38bc4a97f5eca430d43989f0b124.tar.gz rails-ab38aa45497a38bc4a97f5eca430d43989f0b124.tar.bz2 rails-ab38aa45497a38bc4a97f5eca430d43989f0b124.zip |
Update regular expression for checking valid MIME type
MIME Type validation regular expression does not allow for MIME types initialized with strings that contain parameters after the MIME type name.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/mime_type_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index bb3d888e30..50f6c06fee 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -181,6 +181,13 @@ class MimeTypeTest < ActiveSupport::TestCase assert_equal "video/*", Mime::Type.new("video/*").to_s end + test "can be initialized with parameters" do + assert_equal "text/html; parameter", Mime::Type.new("text/html; parameter").to_s + assert_equal "text/html; parameter=abc", Mime::Type.new("text/html; parameter=abc").to_s + assert_equal 'text/html; parameter="abc"', Mime::Type.new('text/html; parameter="abc"').to_s + assert_equal 'text/html; parameter=abc; parameter2="xyz"', Mime::Type.new('text/html; parameter=abc; parameter2="xyz"').to_s + end + test "invalid mime types raise error" do assert_raises Mime::Type::InvalidMimeType do Mime::Type.new("too/many/slash") @@ -191,6 +198,14 @@ class MimeTypeTest < ActiveSupport::TestCase end assert_raises Mime::Type::InvalidMimeType do + Mime::Type.new("improper/semicolon;") + end + + assert_raises Mime::Type::InvalidMimeType do + Mime::Type.new('improper/semicolon; parameter=abc; parameter2="xyz";') + end + + assert_raises Mime::Type::InvalidMimeType do Mime::Type.new("text/html, text/plain") end |