mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 05:13:39 +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 =
|
||||
cooked
|
||||
.css(".mention, .mention-group")
|
||||
.map do |e|
|
||||
.filter_map do |e|
|
||||
if (name = e.inner_text)
|
||||
name = name[1..-1]
|
||||
name = User.normalize_username(name)
|
||||
name
|
||||
User.normalize_username(name[1..-1]) if name[0] == "@"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -569,13 +569,13 @@ RSpec.describe PrettyText do
|
|||
<a class="mention" href="/u/test">@test</a>,
|
||||
<a class="mention-group" href="/g/test-group">@test-group</a>,
|
||||
<a class="custom-mention" href="/custom-mention">@test-custom</a>,
|
||||
<a class="mention" href="/u/test1">test1</a>,
|
||||
this is a test
|
||||
</p>
|
||||
HTML
|
||||
|
||||
extracted_mentions = PrettyText.extract_mentions(Nokogiri::HTML5.fragment(cooked_html))
|
||||
expect(extracted_mentions).to include("test", "test-group")
|
||||
expect(extracted_mentions).not_to include("test-custom")
|
||||
expect(extracted_mentions).to contain_exactly("test", "test-group")
|
||||
|
||||
Plugin::Instance
|
||||
.new
|
||||
|
|
Loading…
Reference in New Issue
Block a user