A platform for community discussion. Free, open, simple.
FIX: Skip unsupported email CSS selectors (#44806)
Samd4c675a92e25
diff --git a/lib/email/styles.rb b/lib/email/styles.rbindex 6ee6e086ff6..5c82f763d2d 100644--- a/lib/email/styles.rb+++ b/lib/email/styles.rb@@ -351,7 +351,12 @@ module Emailenddef format_custom- custom_styles.each { |selector, value| style(selector, value) }+ custom_styles.each do |selector, value|+ style(selector, value)+ rescue Nokogiri::CSS::SyntaxError, Nokogiri::XML::XPath::SyntaxError+ # Custom selectors that cannot be inlined must not prevent email delivery.+ next+ endend# this method is reserved for styles specific to plugindiff --git a/spec/lib/email/styles_spec.rb b/spec/lib/email/styles_spec.rbindex 8de224f74fb..012b175900e 100644--- a/spec/lib/email/styles_spec.rb+++ b/spec/lib/email/styles_spec.rb@@ -57,6 +57,27 @@ RSpec.describe Email::Styles doendend+ describe "custom formatter" do+ ["a:visited", "a:hover", "a["].each do |selector|+ it "skips #{selector} while applying supported custom selectors" do+ SiteSetting.email_custom_css_compiled = <<~CSS+ p { color: red; }+ #{selector}, a:first-child { letter-spacing: 3px; }+ a { background-color: green; }+ CSS++ frag =+ html_fragment(+ '<p>Text</p><div><a href="/">Link</a><a href="/" id="other">Other link</a></div>',+ )++ expect(frag.at("p")["style"]).to include("color:red")+ expect(frag.at("a")["style"]).to include("letter-spacing:3px", "background-color:green")+ expect(frag.at("#other")["style"]).not_to include("letter-spacing:3px")+ end+ end+ end+describe "html template formatter" doit "attaches a style to h3 tags" dofrag = html_fragment("<h3>hello</h3>")