diff --git a/app/models/account.rb b/app/models/account.rb index 1966c5a48b..b6e53cf30a 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -62,7 +62,7 @@ class Account < ApplicationRecord ) USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i - MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)/i + MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)(?:[[:space:]]|$)/i URL_PREFIX_RE = /\Ahttp(s?):\/\/[^\/]+/ include Attachmentable diff --git a/spec/services/process_mentions_service_spec.rb b/spec/services/process_mentions_service_spec.rb index 89b265e9a0..27efd81978 100644 --- a/spec/services/process_mentions_service_spec.rb +++ b/spec/services/process_mentions_service_spec.rb @@ -45,6 +45,19 @@ expect(remote_user.mentions.where(status: status).count).to eq 1 end end + + context 'with a malformed mention' do + let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } + let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}@osueth", visibility: visibility) } + + before do + subject.call(status) + end + + it 'does not create a mention' do + expect(remote_user.mentions.where(status: status).count).to eq 0 + end + end end context 'Temporarily-unreachable ActivityPub user' do