A platform for community discussion. Free, open, simple.
FIX: Remove full nested quotes on direct reply (#8581)
Bianca Nenciu1bccd8eca9b8
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 78372510642..c4cd361dd1a 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -83,7 +83,7 @@ class CookedPostProcessordef remove_full_quote_on_direct_replyreturn if !SiteSetting.remove_full_quotereturn if @post.post_number == 1- return if @doc.css("aside.quote").size != 1+ return if @doc.xpath("aside[contains(@class, 'quote')]").size != 1previous = Post.where("post_number < ? AND topic_id = ? AND post_type = ? AND NOT hidden", @post.post_number, @post.topic_id, Post.types[:regular])@@ -99,7 +99,7 @@ class CookedPostProcessorreturn if previous_text.gsub(/(\s){2,}/, '\1') != quoted_text.gsub(/(\s){2,}/, '\1')- quote_regexp = /\A\s*\[quote.+?\[\/quote\]/im+ quote_regexp = /\A\s*\[quote.+\[\/quote\]/imquoteless_raw = @post.raw.sub(quote_regexp, "").stripreturn if @post.raw.strip == quoteless_rawdiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex 25749d133a3..99fda0ad24f 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -1662,6 +1662,24 @@ describe CookedPostProcessor doRAWend+ let(:raw3) do+ <<~RAW.strip+ [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]++ this is the “first” post++ [/quote]++ [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]++ this is the “first” post++ [/quote]++ and this is the third reply+ RAW+ end+before doSiteSetting.remove_full_quote = trueend@@ -1686,6 +1704,13 @@ describe CookedPostProcessor doendend+ it 'does nothing if there are multiple quotes' do+ reply = Fabricate(:post, topic: topic, raw: raw3)+ CookedPostProcessor.new(reply).remove_full_quote_on_direct_reply+ expect(topic.ordered_posts.pluck(:id)).to eq([post.id, reply.id])+ expect(reply.raw).to eq(raw3)+ end+it 'does not delete quote if not first paragraph' doreply = Fabricate(:post, topic: topic, raw: raw2)CookedPostProcessor.new(reply).remove_full_quote_on_direct_reply@@ -1715,6 +1740,19 @@ describe CookedPostProcessor doexpect(reply.raw).to eq("and this is the third reply")end+ it "works with nested quotes" do+ reply1 = Fabricate(:post, topic: topic, raw: raw)+ reply2 = Fabricate(:post, topic: topic, raw: <<~RAW.strip)+ [quote="#{reply1.user.username}, post:#{reply1.post_number}, topic:#{topic.id}"]+ #{raw}+ [/quote]++ quoting a post with a quote+ RAW++ CookedPostProcessor.new(reply2).remove_full_quote_on_direct_reply+ expect(reply2.raw).to eq('quoting a post with a quote')+ endendend