diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 4b53d53b49..562b4982a7 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -278,7 +278,7 @@ module Email def to_html # needs to be before class + id strip because we need to style redacted # media and also not double-redact already redacted from lower levels - replace_secure_media_urls + replace_secure_media_urls if SiteSetting.secure_media? strip_classes_and_ids replace_relative_urls diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index c98ea50e76..ba25ed4921 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -432,7 +432,7 @@ module PrettyText # images by themselves or inside a onebox doc.css('img[src]').each do |img| - url = if img.parent.classes.include?("aspect-image") + url = if img.parent.classes.include?("aspect-image") && img.attributes["srcset"].present? # we are using the first image from the srcset here so we get the # optimized image instead of the original, because an optimized diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb index 475364b585..84a1e3e204 100644 --- a/spec/components/email/styles_spec.rb +++ b/spec/components/email/styles_spec.rb @@ -188,6 +188,11 @@ describe Email::Styles do end context "replace_secure_media_urls" do + before do + setup_s3 + SiteSetting.secure_media = true + end + let(:attachments) { { 'testimage.png' => stub(url: 'email/test.png') } } it "replaces secure media within a link with a placeholder" do frag = html_fragment("") @@ -208,6 +213,11 @@ describe Email::Styles do end context "inline_secure_images" do + before do + setup_s3 + SiteSetting.secure_media = true + end + let(:attachments) { { 'testimage.png' => stub(url: 'cid:email/test.png') } } fab!(:upload) { Fabricate(:upload, original_filename: 'testimage.png', secure: true, sha1: '123456') } let(:html) { "" }