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