DEV: Add apply_modifier in Email::Renderer for html modifications (#25205)
This commit is contained in:
parent
190a8db55d
commit
66fb2257cf
|
@ -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
|
||||
|
|
|
@ -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 & Peele</h1>"
|
||||
body "<h1>Key & 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
|
||||
|
|
Loading…
Reference in New Issue