mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Treat image/bmp
as a valid content type
This is a follow up to https://github.com/rails/rails/pull/42227#issuecomment-1100927828 The mime types database was incorrect regarding `image/bmp`. It has been fixed in https://github.com/mime-types/mime-types-data/issues/48 and in https://github.com/discourse/mini_mime/pull/45 Since a new version of `mini_mime` hasn't been cut yet, some of the tests in this PR look a bit off. But the core issue of not warning users if they use `image/bmp` is resolved.
This commit is contained in:
parent
8ace32c4cc
commit
a22bb8fa69
5 changed files with 22 additions and 8 deletions
|
@ -362,7 +362,7 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|||
super
|
||||
end
|
||||
|
||||
INVALID_VARIABLE_CONTENT_TYPES_DEPRECATED_IN_RAILS_7 = ["image/jpg", "image/pjpeg", "image/bmp"]
|
||||
INVALID_VARIABLE_CONTENT_TYPES_DEPRECATED_IN_RAILS_7 = ["image/jpg", "image/pjpeg"]
|
||||
INVALID_VARIABLE_CONTENT_TYPES_TO_SERVE_AS_BINARY_DEPRECATED_IN_RAILS_7 = ["text/javascript"]
|
||||
|
||||
private
|
||||
|
|
|
@ -5,30 +5,36 @@ require "database/setup"
|
|||
|
||||
class ActiveStorage::EngineTest < ActiveSupport::TestCase
|
||||
test "all default content types are recognized by mini_mime" do
|
||||
exceptions = ActiveStorage::Blob::INVALID_VARIABLE_CONTENT_TYPES_DEPRECATED_IN_RAILS_7 + ActiveStorage::Blob::INVALID_VARIABLE_CONTENT_TYPES_TO_SERVE_AS_BINARY_DEPRECATED_IN_RAILS_7
|
||||
exceptions = ActiveStorage::Blob::INVALID_VARIABLE_CONTENT_TYPES_DEPRECATED_IN_RAILS_7 +
|
||||
ActiveStorage::Blob::INVALID_VARIABLE_CONTENT_TYPES_TO_SERVE_AS_BINARY_DEPRECATED_IN_RAILS_7 +
|
||||
["image/bmp"] # see https://github.com/discourse/mini_mime/pull/45, once mini_mime is updated this can be removed
|
||||
|
||||
ActiveStorage.variable_content_types.each do |content_type|
|
||||
next if exceptions.include?(content_type) # remove this line in Rails 7.1
|
||||
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type).content_type
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type)&.content_type
|
||||
end
|
||||
|
||||
ActiveStorage.web_image_content_types.each do |content_type|
|
||||
next if exceptions.include?(content_type) # remove this line in Rails 7.1
|
||||
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type).content_type
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type)&.content_type
|
||||
end
|
||||
|
||||
ActiveStorage.content_types_to_serve_as_binary.each do |content_type|
|
||||
next if exceptions.include?(content_type) # remove this line in Rails 7.1
|
||||
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type).content_type
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type)&.content_type
|
||||
end
|
||||
|
||||
ActiveStorage.content_types_allowed_inline.each do |content_type|
|
||||
next if exceptions.include?(content_type) # remove this line in Rails 7.1
|
||||
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type).content_type
|
||||
assert_equal content_type, MiniMime.lookup_by_content_type(content_type)&.content_type
|
||||
end
|
||||
end
|
||||
|
||||
test "image/bmp is a default content type" do
|
||||
assert_includes ActiveStorage.variable_content_types, "image/bmp"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -339,6 +339,10 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
|
|||
assert_not_deprecated do
|
||||
create_blob(filename: "funky.jpg", content_type: "image/jpeg")
|
||||
end
|
||||
|
||||
assert_not_deprecated do
|
||||
create_file_blob(filename: "colors.bmp", content_type: "image/bmp")
|
||||
end
|
||||
end
|
||||
|
||||
test "warning if blob is created with invalid mime type can be disabled" do
|
||||
|
@ -353,6 +357,10 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
|
|||
create_blob(filename: "funky.jpg", content_type: "image/jpeg")
|
||||
end
|
||||
|
||||
assert_not_deprecated do
|
||||
create_file_blob(filename: "colors.bmp", content_type: "image/bmp")
|
||||
end
|
||||
|
||||
ensure
|
||||
ActiveStorage.silence_invalid_content_types_warning = warning_was
|
||||
end
|
||||
|
|
|
@ -104,7 +104,7 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "resized variation of BMP blob" do
|
||||
blob = create_file_blob(filename: "colors.bmp", content_type: "image/x-bmp")
|
||||
blob = create_file_blob(filename: "colors.bmp", content_type: "image/bmp")
|
||||
variant = blob.variant(resize_to_limit: [15, 15]).processed
|
||||
assert_match(/colors\.png/, variant.url)
|
||||
|
||||
|
|
|
@ -2107,7 +2107,7 @@ can transform through ImageMagick.
|
|||
By default, this is defined as:
|
||||
|
||||
```ruby
|
||||
config.active_storage.variable_content_types = %w(image/png image/gif image/jpeg image/tiff image/vnd.adobe.photoshop image/vnd.microsoft.icon image/webp image/avif image/heic image/heif)
|
||||
config.active_storage.variable_content_types = %w(image/png image/gif image/jpeg image/tiff image/bmp image/vnd.adobe.photoshop image/vnd.microsoft.icon image/webp image/avif image/heic image/heif)
|
||||
```
|
||||
|
||||
#### `config.active_storage.web_image_content_types`
|
||||
|
|
Loading…
Reference in a new issue