Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOMERGE] [UNTESTED] Require a word boundary after a mention #39

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/services/process_mentions_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down