FIX: Ignore group mentions inside quotes (#8905)

Also includes:
* DEV: Reuse found elements
This commit is contained in:
Jarek Radosz 2020-02-10 18:31:42 +01:00 committed by GitHub
parent 38011c1d2d
commit 6cfd16656f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -132,7 +132,7 @@ class PostAnalyzer
def cooked_stripped
@cooked_stripped ||= begin
doc = Nokogiri::HTML.fragment(cook(@raw, topic_id: @topic_id))
doc.css("pre .mention, aside.quote > .title, aside.quote .mention, .onebox, .elided").remove
doc.css("pre .mention, aside.quote > .title, aside.quote .mention, aside.quote .mention-group, .onebox, .elided").remove
doc
end
end

View File

@ -447,7 +447,7 @@ module PrettyText
mentions = lookup_mentions(names, user_id: user_id)
doc.css("span.mention").each do |element|
elements.each do |element|
name = element.text[1..-1]
name.downcase!

View File

@ -236,6 +236,13 @@ describe PostAnalyzer do
expect(post_analyzer.raw_mentions).to eq(['finn'])
end
it "ignores group mentions in quotes" do
Fabricate(:group, name: "team")
Fabricate(:group, name: "mods")
post_analyzer = PostAnalyzer.new("[quote=\"Evil Trout\"]\n@team\n[/quote]\n @mods", default_topic_id)
expect(post_analyzer.raw_mentions).to eq(["mods"])
end
it "ignores oneboxes" do
post_analyzer = PostAnalyzer.new("Hello @Jake\n#{url}", default_topic_id)
post_analyzer.stubs(:cook).returns("<p>Hello <span class=\"mention\">@Jake</span><br><a href=\"https://twitter.com/evil_trout/status/345954894420787200\" class=\"onebox\" target=\"_blank\" rel=\"nofollow noopener\">@Finn</a></p>")