mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Append extension to tempfile name
Fixes analyzing an SVG image without an XML declaration. ImageMagick occasionally looks to the extension when it can't discern the type of an image file from its contents. References #31356.
This commit is contained in:
parent
5428c8e3a2
commit
316d87e412
3 changed files with 23 additions and 2 deletions
|
@ -5,7 +5,7 @@ module ActiveStorage
|
|||
private
|
||||
# Opens a new tempfile in #tempdir and copies blob data into it. Yields the tempfile.
|
||||
def download_blob_to_tempfile # :doc:
|
||||
Tempfile.open("ActiveStorage", tempdir) do |file|
|
||||
Tempfile.open([ "ActiveStorage", blob.filename.extension_with_delimiter ], tempdir) do |file|
|
||||
download_blob_to file
|
||||
yield file
|
||||
end
|
||||
|
|
|
@ -6,11 +6,19 @@ require "database/setup"
|
|||
require "active_storage/analyzer/image_analyzer"
|
||||
|
||||
class ActiveStorage::Analyzer::ImageAnalyzerTest < ActiveSupport::TestCase
|
||||
test "analyzing an image" do
|
||||
test "analyzing a JPEG image" do
|
||||
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
|
||||
metadata = blob.tap(&:analyze).metadata
|
||||
|
||||
assert_equal 4104, metadata[:width]
|
||||
assert_equal 2736, metadata[:height]
|
||||
end
|
||||
|
||||
test "analyzing an SVG image without an XML declaration" do
|
||||
blob = create_file_blob(filename: "icon.svg", content_type: "image/svg+xml")
|
||||
metadata = blob.tap(&:analyze).metadata
|
||||
|
||||
assert_equal 792, metadata[:width]
|
||||
assert_equal 584, metadata[:height]
|
||||
end
|
||||
end
|
||||
|
|
13
activestorage/test/fixtures/files/icon.svg
vendored
Normal file
13
activestorage/test/fixtures/files/icon.svg
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!-- The XML declaration is intentionally omitted. -->
|
||||
<svg width="792px" height="584px" viewBox="0 0 792 584" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<path d="M9.51802657,28.724593 C9.51802657,18.2155955 18.1343454,9.60822622 28.6542694,9.60822622 L763.245541,9.60822622 C773.765465,9.60822622 782.381784,18.2155955 782.381784,28.724593 L782.381784,584 L792,584 L792,28.724593 C792,12.911054 779.075522,0 763.245541,0 L28.7544592,0 C12.9244782,0 0,12.911054 0,28.724593 L0,584 L9.61821632,584 C9.51802657,584 9.51802657,28.724593 9.51802657,28.724593 L9.51802657,28.724593 Z" id="Shape" opacity="0.3" fill="#CCCCCC"></path>
|
||||
<circle id="Oval" fill="#FFCC33" cx="119.1" cy="147.2" r="33"></circle>
|
||||
<circle id="Oval" fill="#3399FF" cx="119.1" cy="281.1" r="33"></circle>
|
||||
<circle id="Oval" fill="#FF3333" cx="676.1" cy="376.8" r="33"></circle>
|
||||
<circle id="Oval" fill="#FFCC33" cx="119.1" cy="477.2" r="33"></circle>
|
||||
<rect id="Rectangle-path" opacity="0.75" fill="#CCCCCC" x="176.5" y="130.5" width="442.1" height="33.5"></rect>
|
||||
<rect id="Rectangle-path" opacity="0.75" fill="#CCCCCC" x="176.5" y="183.1" width="442.1" height="33.5"></rect>
|
||||
<rect id="Rectangle-path" opacity="0.75" fill="#CCCCCC" x="176.5" y="265.8" width="442.1" height="33.5"></rect>
|
||||
<rect id="Rectangle-path" opacity="0.75" fill="#CCCCCC" x="176.5" y="363.4" width="442.1" height="33.5"></rect>
|
||||
<rect id="Rectangle-path" opacity="0.75" fill="#CCCCCC" x="176.5" y="465.3" width="442.1" height="33.5"></rect>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in a new issue