Skip to content

Commit b80a2bd

Browse files
Active Storage: upgrade to mini_mime 1.1.0
Fix validating uppercase variant formats. Closes rails#41796.
1 parent 80bd07a commit b80a2bd

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

Gemfile.lock

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ PATH
7575
activerecord (= 7.0.0.alpha)
7676
activesupport (= 7.0.0.alpha)
7777
marcel (~> 1.0.0)
78-
mini_mime (~> 1.0.2)
78+
mini_mime (>= 1.1.0)
7979
activesupport (7.0.0.alpha)
8080
concurrent-ruby (~> 1.0, >= 1.0.2)
8181
i18n (>= 1.6, < 2)
@@ -224,6 +224,9 @@ GEM
224224
tzinfo
225225
event_emitter (0.2.6)
226226
eventmachine (1.2.7)
227+
eventmachine (1.2.7-java)
228+
eventmachine (1.2.7-x64-mingw32)
229+
eventmachine (1.2.7-x86-mingw32)
227230
execjs (2.7.0)
228231
faraday (1.3.0)
229232
faraday-net_http (~> 1.0)
@@ -290,12 +293,14 @@ GEM
290293
hiredis (0.6.3)
291294
hiredis (0.6.3-java)
292295
http_parser.rb (0.6.0)
296+
http_parser.rb (0.6.0-java)
293297
httpclient (2.8.3)
294298
i18n (1.8.7)
295299
concurrent-ruby (~> 1.0)
296300
image_processing (1.12.1)
297301
mini_magick (>= 4.9.5, < 5)
298302
ruby-vips (>= 2.0.17, < 3)
303+
jar-dependencies (0.4.1)
299304
jdbc-mysql (5.1.47)
300305
jdbc-postgres (42.2.14)
301306
jdbc-sqlite3 (3.28.0)
@@ -307,6 +312,7 @@ GEM
307312
mustache
308313
nokogiri
309314
libxml-ruby (3.2.1)
315+
libxml-ruby (3.2.1-x64-mingw32)
310316
listen (3.4.1)
311317
rb-fsevent (~> 0.10, >= 0.10.3)
312318
rb-inotify (~> 0.9, >= 0.9.10)
@@ -319,7 +325,7 @@ GEM
319325
memoist (0.16.2)
320326
method_source (1.0.0)
321327
mini_magick (4.11.0)
322-
mini_mime (1.0.2)
328+
mini_mime (1.1.0)
323329
mini_portile2 (2.5.0)
324330
minitest (5.14.3)
325331
minitest-bisect (1.5.1)
@@ -368,6 +374,8 @@ GEM
368374
pg (1.2.3-x64-mingw32)
369375
pg (1.2.3-x86-mingw32)
370376
psych (3.3.0)
377+
psych (3.3.0-java)
378+
jar-dependencies (>= 0.1.7)
371379
public_suffix (4.0.6)
372380
puma (5.1.1)
373381
nio4r (~> 2.0)
@@ -636,4 +644,4 @@ DEPENDENCIES
636644
websocket-client-simple!
637645

638646
BUNDLED WITH
639-
2.2.3
647+
2.2.15

activestorage/activestorage.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ Gem::Specification.new do |s|
3737
s.add_dependency "activerecord", version
3838

3939
s.add_dependency "marcel", "~> 1.0.0"
40-
s.add_dependency "mini_mime", "~> 1.0.2"
40+
s.add_dependency "mini_mime", ">= 1.1.0"
4141
end

activestorage/app/models/active_storage/variant.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def download(&block)
8989
end
9090

9191
def filename
92-
ActiveStorage::Filename.new "#{blob.filename.base}.#{variation.format}"
92+
ActiveStorage::Filename.new "#{blob.filename.base}.#{variation.format.downcase}"
9393
end
9494

9595
alias_method :content_type_for_serving, :content_type

activestorage/app/models/active_storage/variant_with_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def image
3333
def transform_blob
3434
blob.open do |input|
3535
variation.transform(input) do |output|
36-
yield io: output, filename: "#{blob.filename.base}.#{variation.format}",
36+
yield io: output, filename: "#{blob.filename.base}.#{variation.format.downcase}",
3737
content_type: variation.content_type, service_name: blob.service.name
3838
end
3939
end

activestorage/test/models/variant_test.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,22 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
122122
end
123123
end
124124

125-
test "PNG variation of JPEG blob" do
125+
test "PNG variation of JPEG blob with lowercase format" do
126126
blob = create_file_blob(filename: "racecar.jpg")
127127
variant = blob.variant(format: :png).processed
128128
assert_equal "racecar.png", variant.filename.to_s
129129
assert_equal "image/png", variant.content_type
130130
assert_equal "PNG", read_image(variant).type
131131
end
132132

133+
test "PNG variation of JPEG blob with uppercase format" do
134+
blob = create_file_blob(filename: "racecar.jpg")
135+
variant = blob.variant(format: "PNG").processed
136+
assert_equal "racecar.png", variant.filename.to_s
137+
assert_equal "image/png", variant.content_type
138+
assert_equal "PNG", read_image(variant).type
139+
end
140+
133141
test "variation of invariable blob" do
134142
assert_raises ActiveStorage::InvariableError do
135143
create_file_blob(filename: "report.pdf", content_type: "application/pdf").variant(resize: "100x100")

0 commit comments

Comments
 (0)