A platform for community discussion. Free, open, simple.
DEV: Add apply_modifier in Email::Renderer for html modifications (#25205)
Mark VanLandingham66fb2257cf12
diff --git a/lib/email/renderer.rb b/lib/email/renderer.rbindex a375176e2c8..8b43864dcce 100644--- a/lib/email/renderer.rb+++ b/lib/email/renderer.rb@@ -32,6 +32,7 @@ module Emailstyle.format_basicstyle.format_html+ DiscoursePluginRegistry.apply_modifier(:email_renderer_html, style, @message)style.to_htmlendenddiff --git a/spec/lib/email/renderer_spec.rb b/spec/lib/email/renderer_spec.rbindex 53796146ea6..6a89b270e80 100644--- a/spec/lib/email/renderer_spec.rb+++ b/spec/lib/email/renderer_spec.rb@@ -11,14 +11,28 @@ RSpec.describe Email::Renderer domail.html_part =Mail::Part.new docontent_type "text/html; charset=UTF-8"- body "<h1>Key & Peele</h1>"+ body "<h1>Key & Peele</h1> <a href=\"https://discourse.org\">Discourse link</a>"endend+ let(:renderer) { Email::Renderer.new(message) }+it "escapes HTML entities from text" do- renderer = Email::Renderer.new(message)expect(renderer.text).to eq("Key & Peele")end++ context "with email_renderer_html modifier" do+ it "can modify the html" do+ Plugin::Instance+ .new+ .register_modifier(:email_renderer_html) do |styles, _|+ styles.fragment.css("a").each { |link| link["href"] = "httpz://hijacked.sorry" }+ end++ expect(renderer.html).not_to include("href=\"https://discourse.org\"")+ expect(renderer.html).to include("href=\"httpz://hijacked.sorry\"")+ end+ endend