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) FileHelper.optimize_image!(to)
true true
rescue => e rescue => e
if Rails.env.test?
raise e
else
Rails.logger.error("Could not optimize image #{to}: #{e.message}") Rails.logger.error("Could not optimize image #{to}: #{e.message}")
false false
end end
end
def self.migrate_to_new_scheme(limit = nil) def self.migrate_to_new_scheme(limit = nil)
problems = [] 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) File.delete(tmp_path) if File.exists?(tmp_path)
end end
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 end
describe '.downsize' do describe '.downsize' do