mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: always test and coerce to image on upload
In the past the filename of the origin was used as the source for the extension of the file when optimizing on upload. We now use the actual calculated extension based on upload data.
This commit is contained in:
@ -27,6 +27,32 @@ describe OptimizedImage do
|
||||
end
|
||||
|
||||
describe '.resize' do
|
||||
it 'should work correctly when extension is bad' do
|
||||
|
||||
original_path = Dir::Tmpname.create(['origin', '.bin']) { nil }
|
||||
|
||||
begin
|
||||
FileUtils.cp "#{Rails.root}/spec/fixtures/images/logo.png", original_path
|
||||
|
||||
# we use "filename" to get the correct extension here, it is more important
|
||||
# then any other param
|
||||
|
||||
OptimizedImage.resize(
|
||||
original_path,
|
||||
original_path,
|
||||
5,
|
||||
5,
|
||||
filename: "test.png"
|
||||
)
|
||||
|
||||
expect(File.read(original_path)).to eq(
|
||||
File.read("#{Rails.root}/spec/fixtures/images/resized.png")
|
||||
)
|
||||
ensure
|
||||
File.delete(original_path) if File.exists?(original_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should work correctly' do
|
||||
tmp_path = "/tmp/resized.png"
|
||||
|
||||
|
Reference in New Issue
Block a user