diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index 3687b48f788..663e0662c22 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -252,8 +252,12 @@ class OptimizedImage < ActiveRecord::Base FileHelper.optimize_image!(to) true rescue => e - Rails.logger.error("Could not optimize image #{to}: #{e.message}") - false + 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) diff --git a/spec/fixtures/images/svg.png b/spec/fixtures/images/svg.png new file mode 100644 index 00000000000..4c9c03731b3 --- /dev/null +++ b/spec/fixtures/images/svg.png @@ -0,0 +1,3 @@ + + + diff --git a/spec/models/optimized_image_spec.rb b/spec/models/optimized_image_spec.rb index 23268160927..60441d872f0 100644 --- a/spec/models/optimized_image_spec.rb +++ b/spec/models/optimized_image_spec.rb @@ -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