From 34a14112a70e85ad4abc7300db0f4cae05ead3e0 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 20 Mar 2024 12:20:15 +1100 Subject: [PATCH] FIX: remove "fake" mentions from extract_mentions (#26253) ``` bsam ``` Is not a mention of the user sam. We expect an @ in front always. --- lib/pretty_text.rb | 6 ++---- spec/lib/pretty_text_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 17c0ab06f0f..aed31e1a912 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -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 diff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rb index 24bd6c79b0d..fef6b44ba4e 100644 --- a/spec/lib/pretty_text_spec.rb +++ b/spec/lib/pretty_text_spec.rb @@ -569,13 +569,13 @@ RSpec.describe PrettyText do @test, @test-group, @test-custom, + test1, this is a test

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