Compare commits

...

6 Commits

Author SHA1 Message Date
Mischa Holz
965203a094
Merge a04273b06d into e9170e2de1 2025-07-09 17:04:29 +00:00
Mischa Holz
a04273b06d
Merge branch 'main' into emoji-mentions 2025-01-23 11:22:31 +01:00
Mischa Holz
efffde0230
Add semicolon 2024-11-29 20:50:45 +01:00
Mischa Holz
fd4c869f63
Replace the domain part of the mention regex with twitter's validDomain 2024-11-29 20:50:43 +01:00
Mischa Holz
e7d0e511a9
Add a test for unicode domain name mentions 2024-11-29 20:50:41 +01:00
Mischa Holz
1b909c98ab
Use TwitterText regex for valid domains in mentions
TwitterText already has a regex to check for valid domains that allows a
few domains the current Regex did not allow. Mainly it allows mentions
of accounts on domains with emoji in their domain names to be processed
correctly.

Mentions like `@test@🌈🌈🌈.st` will now work correctly.
2024-11-29 20:50:32 +01:00
3 changed files with 17 additions and 2 deletions

View File

@ -1,9 +1,20 @@
import regexSupplant from 'twitter-text/dist/lib/regexSupplant';
import validDomain from 'twitter-text/dist/regexp/validDomain';
import { urlRegex } from './url_regex'; import { urlRegex } from './url_regex';
const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx'; const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx';
const validMention = regexSupplant(
'(^|[^/\\w])@(([a-z0-9_]+)@(#{validDomain}))',
{
validDomain,
},
'ig'
);
export function countableText(inputText) { export function countableText(inputText) {
return inputText return inputText
.replace(urlRegex, urlPlaceholder) .replace(urlRegex, urlPlaceholder)
.replace(/(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, '$1@$3'); .replace(validMention, '$1@$3');
} }

View File

@ -71,7 +71,7 @@ class Account < ApplicationRecord
INSTANCE_ACTOR_ID = -99 INSTANCE_ACTOR_ID = -99
USERNAME_RE = /[a-z0-9_]+([.-]+[a-z0-9_]+)*/i USERNAME_RE = /[a-z0-9_]+([.-]+[a-z0-9_]+)*/i
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]]+([.-]+[[:word:]]+)*)?)} MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@#{Twitter::TwitterText::Regex[:valid_domain]})?)}
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+} URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
USERNAME_LENGTH_LIMIT = 30 USERNAME_LENGTH_LIMIT = 30

View File

@ -401,6 +401,10 @@ RSpec.describe Account do
expect(subject.match('@alice@example.com')[1]).to eq 'alice@example.com' expect(subject.match('@alice@example.com')[1]).to eq 'alice@example.com'
end end
it 'matches full usernames with unicode domain names' do
expect(subject.match('@alice@🌈🌈🌈.st')[1]).to eq 'alice@🌈🌈🌈.st'
end
it 'matches full usernames with a dot at the end' do it 'matches full usernames with a dot at the end' do
expect(subject.match('Hello @alice@example.com.')[1]).to eq 'alice@example.com' expect(subject.match('Hello @alice@example.com.')[1]).to eq 'alice@example.com'
end end