diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 0ed10099efd..8dea3107554 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -449,9 +449,16 @@ module PrettyText img['src'] end - width = img.classes.include?('site-icon') ? 16 : img['width'] - height = img.classes.include?('site-icon') ? 16 : img['height'] - oneboxed = (img.parent&.parent&.classes || []).include?('onebox-body') + width = img['width'] + height = img['height'] + oneboxed = img.ancestors.css(".onebox-body").any? || img.classes.include?("onebox-avatar") + + # we always want this to be tiny and without any special styles + if img.classes.include?('site-icon') + oneboxed = false + width = 16 + height = 16 + end if Upload.secure_media_url?(url) img.add_next_sibling secure_media_placeholder(doc, url, oneboxed: oneboxed, width: width, height: height) diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb index 8776d5019a4..382f1a11d64 100644 --- a/spec/components/email/styles_spec.rb +++ b/spec/components/email/styles_spec.rb @@ -330,6 +330,38 @@ describe Email::Styles do expect(@frag.css('[data-embedded-secure-image]')[0].attr('style')).to eq('width: 16px; height: 16px;') expect(@frag.css('[data-embedded-secure-image]')[1].attr('style')).to eq('width: 60px; max-height: 80%; max-width: 20%; height: auto; float: left; margin-right: 10px;') end + + context "when inlining a oneboxed image with a direct parent of onebox-body" do + let(:html) do + <<~HTML + + HTML + end + + it "keeps the special onebox styles" do + strip_and_inline + expect(@frag.to_s).to include("cid:email/test.png") + expect(@frag.to_s).to include("cid:email/test2.ico") + expect(@frag.css('[data-sripped-secure-media]')).not_to be_present + expect(@frag.css('[data-embedded-secure-image]')[1].attr('style')).to eq('width: 60px; max-height: 80%; max-width: 20%; height: auto; float: left; margin-right: 10px;') + end + end end end end