mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 22:13:45 +08:00
FIX: remove "fake" mentions from extract_mentions (#26253)
``` <a class="mention" href="/u/test1">bsam</a> ``` Is not a mention of the user sam. We expect an @ in front always.
This commit is contained in:
parent
4ca41e0af2
commit
34a14112a7
|
@ -464,11 +464,9 @@ module PrettyText
|
||||||
mentions =
|
mentions =
|
||||||
cooked
|
cooked
|
||||||
.css(".mention, .mention-group")
|
.css(".mention, .mention-group")
|
||||||
.map do |e|
|
.filter_map do |e|
|
||||||
if (name = e.inner_text)
|
if (name = e.inner_text)
|
||||||
name = name[1..-1]
|
User.normalize_username(name[1..-1]) if name[0] == "@"
|
||||||
name = User.normalize_username(name)
|
|
||||||
name
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -569,13 +569,13 @@ RSpec.describe PrettyText do
|
||||||
<a class="mention" href="/u/test">@test</a>,
|
<a class="mention" href="/u/test">@test</a>,
|
||||||
<a class="mention-group" href="/g/test-group">@test-group</a>,
|
<a class="mention-group" href="/g/test-group">@test-group</a>,
|
||||||
<a class="custom-mention" href="/custom-mention">@test-custom</a>,
|
<a class="custom-mention" href="/custom-mention">@test-custom</a>,
|
||||||
|
<a class="mention" href="/u/test1">test1</a>,
|
||||||
this is a test
|
this is a test
|
||||||
</p>
|
</p>
|
||||||
HTML
|
HTML
|
||||||
|
|
||||||
extracted_mentions = PrettyText.extract_mentions(Nokogiri::HTML5.fragment(cooked_html))
|
extracted_mentions = PrettyText.extract_mentions(Nokogiri::HTML5.fragment(cooked_html))
|
||||||
expect(extracted_mentions).to include("test", "test-group")
|
expect(extracted_mentions).to contain_exactly("test", "test-group")
|
||||||
expect(extracted_mentions).not_to include("test-custom")
|
|
||||||
|
|
||||||
Plugin::Instance
|
Plugin::Instance
|
||||||
.new
|
.new
|
||||||
|
|
Loading…
Reference in New Issue
Block a user