A platform for community discussion. Free, open, simple.
FIX: Do not optimize animated images in cooked posts (#11214)
Bianca Nenciue98c7b15d6ce
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 6f11b3891c2..fb61f24b1a8 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -384,7 +384,7 @@ class CookedPostProcessorw, h = img["width"].to_i, img["height"].to_i# note: optimize_urls cooks the src and data-small-upload further after this- thumbnail = upload.thumbnail(w, h)+ thumbnail = !upload.animated && upload.thumbnail(w, h)if thumbnail && thumbnail.filesize.to_i < upload.filesizeimg["src"] = thumbnail.urldiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex dc5842f0e3c..fd2cd6c7823 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -960,6 +960,19 @@ describe CookedPostProcessor doexpect(doc.css('img').first['srcset']).to_not eq(nil)end+ it "does not optimize animated images" do+ upload.update!(animated: true)+ post = Fabricate(:post, raw: "")++ cpp = CookedPostProcessor.new(post, disable_loading_image: true)+ cpp.post_process++ doc = Nokogiri::HTML5::fragment(cpp.html)+ expect(doc.css('.lightbox-wrapper').size).to eq(1)+ expect(doc.css('img').first['src']).to include(upload.url)+ expect(doc.css('img').first['srcset']).to eq(nil)+ end+it "optimizes images in quotes" dopost = Fabricate(:post, raw: <<~MD)[quote]