mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 22:47:46 +08:00
FIX: Remove full nested quotes on direct reply (#8581)
It used to check how many quotes were inside a post, without taking considering that some quotes can contain other quotes. This commit selects only top level quotes. I had to use XPath because I could not find an equivalent CSS selector.
This commit is contained in:
@ -1662,6 +1662,24 @@ describe CookedPostProcessor do
|
||||
RAW
|
||||
end
|
||||
|
||||
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 do
|
||||
SiteSetting.remove_full_quote = true
|
||||
end
|
||||
@ -1686,6 +1704,13 @@ describe CookedPostProcessor do
|
||||
end
|
||||
end
|
||||
|
||||
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' do
|
||||
reply = Fabricate(:post, topic: topic, raw: raw2)
|
||||
CookedPostProcessor.new(reply).remove_full_quote_on_direct_reply
|
||||
@ -1715,6 +1740,19 @@ describe CookedPostProcessor do
|
||||
expect(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')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user