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:
Sam 2024-03-20 12:20:15 +11:00 committed by GitHub
parent 4ca41e0af2
commit 34a14112a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 6 deletions

View File

@ -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

View File

@ -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