Skip to content

A platform for community discussion. Free, open, simple.

Revert "FIX: deduplicate css in mails (#30003)" (#30013)

Jarek Radosz85ead5ac7a6e
diff --git a/lib/email/styles.rb b/lib/email/styles.rb
index c378d0d7a05..48b051cd88a 100644
--- a/lib/email/styles.rb
+++ b/lib/email/styles.rb
@@ -374,31 +374,12 @@ module Email
end
end
- def deduplicate_style(style)
- styles = {}
-
- style
- .split(";")
- .select(&:present?)
- .map { _1.split(":", 2).map(&:strip) }
- .each { |k, v| styles[k] = v if k.present? && v.present? }
-
- styles.map { |k, v| "#{k}:#{v}" }.join(";")
- end
-
- def deduplicate_styles
- @fragment
- .css("[style]")
- .each { |element| element["style"] = deduplicate_style element["style"] }
- end
-
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_uploads_urls if SiteSetting.secure_uploads?
strip_classes_and_ids
replace_relative_urls
- deduplicate_styles
@fragment.to_html
end
diff --git a/spec/lib/email/styles_spec.rb b/spec/lib/email/styles_spec.rb
index 4135fdb9a37..e7822da2cf9 100644
--- a/spec/lib/email/styles_spec.rb
+++ b/spec/lib/email/styles_spec.rb
@@ -168,24 +168,6 @@ RSpec.describe Email::Styles do
end
end
- describe "deduplicate styles" do
- it "removes double definitions" do
- frag = "<test style='color:green;color:red'>hello</test>"
- styler = Email::Styles.new(frag)
- styled = styler.to_html
- styled = Nokogiri::HTML5.fragment(styled)
- expect(styled.at("test")["style"]).to eq("color:red")
- end
- it "handles whitespace correctly" do
- frag =
- "<test style=' color : green ; ; ; color : red; background:white; background:yellow '>hello</test>"
- styler = Email::Styles.new(frag)
- styled = styler.to_html
- styled = Nokogiri::HTML5.fragment(styled)
- expect(styled.at("test")["style"]).to eq("color:red;background:yellow")
- end
- end
-
describe "dark mode emails" do
it "adds dark_mode_styles when site setting active" do
frag = html_fragment('<div class="body">test</div>')