From e10920eb20e105ef3ee4cd81afe4c8a9f0039f19 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 1 Sep 2021 22:06:40 +0200 Subject: [PATCH] Fix processing mentions to domains with non-ascii TLDs (#16689) Fixes #16602 --- app/models/account.rb | 2 +- spec/services/process_mentions_service_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index 9069b292f5..007adc409b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -56,7 +56,7 @@ class Account < ApplicationRecord USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i - MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[a-z0-9]+)?)/i + MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)/i URL_PREFIX_RE = /\Ahttp(s?):\/\/[^\/]+/ include AccountAssociations diff --git a/spec/services/process_mentions_service_spec.rb b/spec/services/process_mentions_service_spec.rb index c30de8eeb9..69f8310c2f 100644 --- a/spec/services/process_mentions_service_spec.rb +++ b/spec/services/process_mentions_service_spec.rb @@ -73,6 +73,24 @@ RSpec.describe ProcessMentionsService, type: :service do 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