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

This reverts commit 6e726d436f51924083829bfe14ffa0a8f7f44985.

The specs were failing in the original PR but the CI didn't run.
This commit is contained in:
Jarek Radosz 2024-11-30 15:32:32 +01:00 committed by GitHub
parent 6e726d436f
commit 85ead5ac7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 37 deletions

View File

@ -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

View File

@ -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>')