Skip to content

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

FEATURE: Remove full quote only if first paragraph. (#6793)

Bianca Nenciu825ae868579d
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 910f59e7387..a8ad6ad1731 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -95,7 +95,7 @@ class CookedPostProcessor
prev = Post.where('post_number < ? AND topic_id = ? AND post_type = ? AND not hidden', @post.post_number, @post.topic_id, Post.types[:regular]).order('post_number desc').limit(1).pluck(:raw).first
return if !prev
- new_raw = @post.raw.gsub(/\[quote[^\]]*\]\s*#{Regexp.quote(prev.strip)}\s*\[\/quote\]/, '')
+ new_raw = @post.raw.gsub(/\A\s*\[quote[^\]]*\]\s*#{Regexp.quote(prev.strip)}\s*\[\/quote\]/, '')
return if @post.raw == new_raw
PostRevisor.new(@post).revise!(
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 8a84857fdd5..0c5d05c20a3 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -1153,6 +1153,7 @@ describe CookedPostProcessor do
context "remove direct reply full quote" do
let(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
+
let(:raw) do
<<~RAW
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
@@ -1163,6 +1164,16 @@ describe CookedPostProcessor do
RAW
end
+ let(:raw2) do
+ <<~RAW
+ and this is the third reply
+
+ [quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
+ this is the first post
+ [/quote]
+ RAW
+ end
+
it 'works' do
SiteSetting.remove_full_quote = true
@@ -1183,6 +1194,15 @@ describe CookedPostProcessor do
end
end
+ it 'does not delete quote if not first paragraph' do
+ SiteSetting.remove_full_quote = true
+
+ reply = Fabricate(:post, topic: topic, raw: raw2)
+ CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
+ expect(topic.posts).to eq([post, reply])
+ expect(reply.raw).to eq(raw2)
+ end
+
it "does nothing when 'remove_full_quote' is disabled" do
SiteSetting.remove_full_quote = false