This commit is contained in:
Guo Xiang Tan 2018-07-26 09:16:14 +08:00
parent f94aeaf6cf
commit 30242972d3
3 changed files with 28 additions and 2 deletions

View File

@ -252,9 +252,13 @@ class OptimizedImage < ActiveRecord::Base
FileHelper.optimize_image!(to)
true
rescue => e
if Rails.env.test?
raise e
else
Rails.logger.error("Could not optimize image #{to}: #{e.message}")
false
end
end
def self.migrate_to_new_scheme(limit = nil)
problems = []

3
spec/fixtures/images/svg.png vendored Normal file
View File

@ -0,0 +1,3 @@
<svg width="1" height="1">
<image xlink:href="https://www.discourse.org" />
</svg>

After

Width:  |  Height:  |  Size: 83 B

View File

@ -45,6 +45,25 @@ describe OptimizedImage do
File.delete(tmp_path) if File.exists?(tmp_path)
end
end
describe 'when an svg with a href is masked as a png' do
it 'should not trigger the external request' do
tmp_path = "/tmp/resized.png"
begin
expect do
OptimizedImage.resize(
"#{Rails.root}/spec/fixtures/images/svg.png",
tmp_path,
5,
5
)
end.to raise_error(RuntimeError, /improper image header/)
ensure
File.delete(tmp_path) if File.exists?(tmp_path)
end
end
end
end
describe '.downsize' do