From 3b06e5502b6f36cea2245f770d78cf9a11f89210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 8 Feb 2018 00:01:11 +0100 Subject: [PATCH] FIX: ensure we never send elided content via email --- plugins/discourse-details/plugin.rb | 6 +++++- .../spec/components/pretty_text_spec.rb | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) 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 = "
foobar
" - expect(PrettyText.cook("
foobar
")).to match_html(cooked_html) - cooked_html = <<~HTML
@@ -14,7 +11,16 @@ describe PrettyText do

bar

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
42
") + mail_html = PrettyText.cook("Hello World") + + expect(PrettyText.format_for_email(cooked_html)).to match_html(mail_html) end end