mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: ignore self-quotes from the same post when saving (#6082)
This commit is contained in:
parent
ba7a8db0e8
commit
f2cc05c6c6
@ -630,7 +630,9 @@ class Post < ActiveRecord::Base
|
|||||||
raw.scan(/\[quote=\"([^"]+)"\]/).each do |quote|
|
raw.scan(/\[quote=\"([^"]+)"\]/).each do |quote|
|
||||||
args = parse_quote_into_arguments(quote)
|
args = parse_quote_into_arguments(quote)
|
||||||
# If the topic attribute is present, ensure it's the same topic
|
# 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
|
end
|
||||||
|
|
||||||
temp_collector.uniq!
|
temp_collector.uniq!
|
||||||
|
@ -19,6 +19,8 @@ class QuotedPost < ActiveRecord::Base
|
|||||||
|
|
||||||
next if topic_id == 0 || post_number == 0
|
next if topic_id == 0 || post_number == 0
|
||||||
next if uniq[[topic_id, post_number]]
|
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
|
uniq[[topic_id, post_number]] = true
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -744,6 +744,12 @@ describe Post do
|
|||||||
expect(reply.quoted_post_numbers).to be_blank
|
expect(reply.quoted_post_numbers).to be_blank
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'a new reply' do
|
describe 'a new reply' do
|
||||||
|
@ -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)
|
expect(QuotedPost.where(post_id: post4.id).pluck(:quoted_post_id)).to contain_exactly(post1.id, post2.id, post5.id)
|
||||||
end
|
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
|
it 'correctly handles deltas' do
|
||||||
post1 = Fabricate(:post)
|
post1 = Fabricate(:post)
|
||||||
post2 = Fabricate(:post)
|
post2 = Fabricate(:post)
|
||||||
|
Loading…
Reference in New Issue
Block a user