DEV: Add apply_modifier in Email::Renderer for html modifications (#25205)

This commit is contained in:
Mark VanLandingham 2024-01-12 09:14:55 -06:00 committed by GitHub
parent 190a8db55d
commit 66fb2257cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -32,6 +32,7 @@ module Email
style.format_basic
style.format_html
DiscoursePluginRegistry.apply_modifier(:email_renderer_html, style, @message)
style.to_html
end
end

View File

@ -11,14 +11,28 @@ RSpec.describe Email::Renderer do
mail.html_part =
Mail::Part.new do
content_type "text/html; charset=UTF-8"
body "<h1>Key &amp; Peele</h1>"
body "<h1>Key &amp; Peele</h1> <a href=\"https://discourse.org\">Discourse link</a>"
end
mail
end
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
end
end