From ab38aa45497a38bc4a97f5eca430d43989f0b124 Mon Sep 17 00:00:00 2001 From: Cliff Pruitt Date: Tue, 19 Mar 2019 10:57:55 -0400 Subject: 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. --- actionpack/test/dispatch/mime_type_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionpack/test/dispatch') 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") @@ -190,6 +197,14 @@ class MimeTypeTest < ActiveSupport::TestCase Mime::Type.new("missingslash") 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 -- cgit v1.2.3