Skip to content

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

FIX: ensure we never send elided content via email

Régis Hanol3b06e5502b6f
diff --git a/plugins/discourse-details/plugin.rb b/plugins/discourse-details/plugin.rb
index 116836d74cd..8b537509b96 100644
--- a/plugins/discourse-details/plugin.rb
+++ b/plugins/discourse-details/plugin.rb
@@ -13,7 +13,7 @@ after_initialize do
Email::Styles.register_plugin_style do |fragment|
# remove all elided content
- fragment.css("details.elided").each { |d| d.remove }
+ fragment.css("details.elided").each(&:remove)
# replace all details with their summary in emails
fragment.css("details").each do |details|
@@ -28,4 +28,8 @@ after_initialize do
end
end
+ on(:reduce_cooked) do |fragment|
+ fragment.css("details.elided").each(&:remove)
+ end
+
end
diff --git a/plugins/discourse-details/spec/components/pretty_text_spec.rb b/plugins/discourse-details/spec/components/pretty_text_spec.rb
index cd03a2fb6ba..338e10f4c31 100644
--- a/plugins/discourse-details/spec/components/pretty_text_spec.rb
+++ b/plugins/discourse-details/spec/components/pretty_text_spec.rb
@@ -4,9 +4,6 @@ require 'pretty_text'
describe PrettyText do
it "supports details tag" do
- cooked_html = "<details><summary>foo</summary>bar</details>"
- expect(PrettyText.cook("<details><summary>foo</summary>bar</details>")).to match_html(cooked_html)
-
cooked_html = <<~HTML
<details>
<summary>
@@ -14,7 +11,16 @@ describe PrettyText do
<p>bar</p>
</details>
HTML
- expect(PrettyText.cook("[details=foo]\nbar\n[/details]")).to eq(cooked_html.strip)
+
+ expect(cooked_html).to match_html(cooked_html)
+ expect(PrettyText.cook("[details=foo]\nbar\n[/details]")).to match_html(cooked_html)
+ end
+
+ it "deletes elided content" do
+ cooked_html = PrettyText.cook("Hello World\n\n<details class='elided'>42</details>")
+ mail_html = PrettyText.cook("Hello World")
+
+ expect(PrettyText.format_for_email(cooked_html)).to match_html(mail_html)
end
end