A platform for community discussion. Free, open, simple.
FIX: Ignore group mentions inside quotes (#8905)
Jarek Radosz6cfd16656f02
diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rbindex 1b5ca6970e9..63fe9724b4d 100644--- a/app/models/post_analyzer.rb+++ b/app/models/post_analyzer.rb@@ -132,7 +132,7 @@ class PostAnalyzerdef cooked_stripped@cooked_stripped ||= begindoc = 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").removedocendenddiff --git a/lib/pretty_text.rb b/lib/pretty_text.rbindex a09b45fb13f..e5c7fff2106 100644--- a/lib/pretty_text.rb+++ b/lib/pretty_text.rb@@ -447,7 +447,7 @@ module PrettyTextmentions = 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!diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rbindex 14afb3f80ec..d74b72a4e1c 100644--- a/spec/models/post_analyzer_spec.rb+++ b/spec/models/post_analyzer_spec.rb@@ -236,6 +236,13 @@ describe PostAnalyzer doexpect(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" dopost_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>")