FIX: ignore self-quotes from the same post when saving (#6082)

This commit is contained in:
OsamaSayegh 2018-07-10 11:17:28 +03:00 committed by Guo Xiang Tan
parent ba7a8db0e8
commit f2cc05c6c6
4 changed files with 33 additions and 1 deletions

View File

@ -630,7 +630,9 @@ class Post < ActiveRecord::Base
raw.scan(/\[quote=\"([^"]+)"\]/).each do |quote|
args = parse_quote_into_arguments(quote)
# If the topic attribute is present, ensure it's the same topic
temp_collector << args[:post] unless (args[:topic].present? && topic_id != args[:topic])
if !(args[:topic].present? && topic_id != args[:topic]) && args[:post] != post_number
temp_collector << args[:post]
end
end
temp_collector.uniq!

View File

@ -19,6 +19,8 @@ class QuotedPost < ActiveRecord::Base
next if topic_id == 0 || post_number == 0
next if uniq[[topic_id, post_number]]
next if post.topic_id == topic_id && post.post_number == post_number
uniq[[topic_id, post_number]] = true
begin

View File

@ -744,6 +744,12 @@ describe Post do
expect(reply.quoted_post_numbers).to be_blank
end
it "doesn't find the quote in the same post" do
reply = Fabricate.build(:post, post_args.merge(post_number: 646))
reply.raw = "[quote=\"EvilTrout, post:#{reply.post_number}, topic:#{post.topic_id}\"]hello[/quote]"
reply.extract_quoted_post_numbers
expect(reply.quoted_post_numbers).to be_blank
end
end
describe 'a new reply' do

View File

@ -33,6 +33,28 @@ describe QuotedPost do
expect(QuotedPost.where(post_id: post4.id).pluck(:quoted_post_id)).to contain_exactly(post1.id, post2.id, post5.id)
end
it "doesn't count quotes from the same post" do
SiteSetting.queue_jobs = false
topic = Fabricate(:topic)
post = create_post(topic: topic, post_number: 1, raw: "foo bar")
post.cooked = <<-HTML
<aside class="quote" data-post="#{post.post_number}" data-topic="#{post.topic_id}">
<div class="title">
<div class="quote-controls"></div>
<img width="20" height="20" src="/user_avatar/meta.discourse.org/techapj/20/3281.png" class="avatar">techAPJ:
</div>
<blockquote><p>When the user will v</p></blockquote>
</aside>
HTML
post.save!
QuotedPost.extract_from(post)
expect(QuotedPost.where(post_id: post.id).count).to eq(0)
expect(QuotedPost.where(quoted_post_id: post.id).count).to eq(0)
end
it 'correctly handles deltas' do
post1 = Fabricate(:post)
post2 = Fabricate(:post)