mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Active Storage: don't crash if mini_mime doesn't recognize content_type
Fixes https://github.com/rails/rails/issues/41777
This commit is contained in:
parent
10d74dbe86
commit
fbcac360b2
2 changed files with 15 additions and 1 deletions
|
@ -113,7 +113,7 @@ module ActiveStorage::Blob::Representable
|
|||
if filename.extension.present? && MiniMime.lookup_by_extension(filename.extension)&.content_type == content_type
|
||||
filename.extension
|
||||
else
|
||||
MiniMime.lookup_by_content_type(content_type).extension
|
||||
MiniMime.lookup_by_content_type(content_type)&.extension
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -187,6 +187,20 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "doesn't crash content_type not recognized by mini_mime" do
|
||||
blob = create_file_blob(filename: "racecar.jpg")
|
||||
|
||||
# image/jpg is not recognised by mini_mime (image/jpeg is correct)
|
||||
blob.update(content_type: "image/jpg")
|
||||
|
||||
assert_nothing_raised do
|
||||
blob.variant(resize: "100x100")
|
||||
end
|
||||
|
||||
assert_nil blob.send(:format)
|
||||
assert_equal :png, blob.send(:default_variant_format)
|
||||
end
|
||||
|
||||
private
|
||||
def process_variants_with(processor)
|
||||
previous_processor, ActiveStorage.variant_processor = ActiveStorage.variant_processor, processor
|
||||
|
|
Loading…
Reference in a new issue