mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 12:46:14 +08:00
FIX: Ignore group mentions inside quotes (#8905)
Also includes: * DEV: Reuse found elements
This commit is contained in:
parent
38011c1d2d
commit
6cfd16656f
|
@ -132,7 +132,7 @@ class PostAnalyzer
|
||||||
def cooked_stripped
|
def cooked_stripped
|
||||||
@cooked_stripped ||= begin
|
@cooked_stripped ||= begin
|
||||||
doc = Nokogiri::HTML.fragment(cook(@raw, topic_id: @topic_id))
|
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
|
doc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -447,7 +447,7 @@ module PrettyText
|
||||||
|
|
||||||
mentions = lookup_mentions(names, user_id: user_id)
|
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 = element.text[1..-1]
|
||||||
name.downcase!
|
name.downcase!
|
||||||
|
|
||||||
|
|
|
@ -236,6 +236,13 @@ describe PostAnalyzer do
|
||||||
expect(post_analyzer.raw_mentions).to eq(['finn'])
|
expect(post_analyzer.raw_mentions).to eq(['finn'])
|
||||||
end
|
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
|
it "ignores oneboxes" do
|
||||||
post_analyzer = PostAnalyzer.new("Hello @Jake\n#{url}", default_topic_id)
|
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>")
|
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>")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user