Skip to content

Commit

Permalink
Fix processing mentions to domains with non-ascii TLDs (mastodon#16689)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and kadoshita committed Nov 6, 2021
1 parent e86cc31 commit 3cafb51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Account < ApplicationRecord
hub_url
)

USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[a-z0-9]+)?)/i
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)/i

include AccountAssociations
include AccountAvatar
Expand Down
18 changes: 18 additions & 0 deletions spec/services/process_mentions_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@
expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
end
end

context 'with an IDN TLD' do
let(:remote_user) { Fabricate(:account, username: 'foo', protocol: :activitypub, domain: 'xn--y9a3aq.xn--y9a3aq', inbox_url: 'http://example.com/inbox') }
let(:status) { Fabricate(:status, account: account, text: "Hello @foo@հայ.հայ") }

before do
stub_request(:post, remote_user.inbox_url)
subject.call(status)
end

it 'creates a mention' do
expect(remote_user.mentions.where(status: status).count).to eq 1
end

it 'sends activity to the inbox' do
expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
end
end
end

context 'Temporarily-unreachable ActivityPub user' do
Expand Down

0 comments on commit 3cafb51

Please sign in to comment.