From 9d9332d8c96906df992d5b78a8aa545bb7ea769d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sun, 13 May 2018 18:23:17 +0200 Subject: [PATCH] FIX: allow user quotes in HTML digest emails --- app/helpers/user_notifications_helper.rb | 4 +++- spec/helpers/user_notifications_helper_spec.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index dd57d457943..b284f69c611 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -37,13 +37,15 @@ module UserNotificationsHelper result = "" length = 0 - doc.css('body > p, aside.onebox, body > ul').each do |node| + + doc.css('body > p, aside.onebox, body > ul, body > blockquote').each do |node| if node.text.present? result << node.to_s length += node.inner_text.length return result if length >= SiteSetting.digest_min_excerpt_length end end + return result unless result.blank? # If there is no first paragaph, return the first div (onebox) diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rb index dcd5cdcfce0..32e1f140809 100644 --- a/spec/helpers/user_notifications_helper_spec.rb +++ b/spec/helpers/user_notifications_helper_spec.rb @@ -34,5 +34,23 @@ describe UserNotificationsHelper do SiteSetting.digest_min_excerpt_length = 50 expect(helper.email_excerpt(arg)).to eq([with_link, paragraphs[0]].join) end + + it "uses user quotes but not post quotes" do + cooked = <<~HTML +

BEFORE

+
+

This is a user quote

+
+ +

AFTER

+ HTML + + expect(helper.email_excerpt(cooked)).to eq "

BEFORE

\n

This is a user quote

\n

AFTER

" + end end end