This commit is contained in:
Mischa Holz 2024-05-17 14:05:41 +00:00 committed by GitHub
commit 20b66a81f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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';
const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx';
const validMention = regexSupplant(
'(^|[^/\\w])@(([a-z0-9_]+)@(#{validDomain}))',
{
validDomain,
},
'ig'
);
export function countableText(inputText) {
return inputText
.replace(urlRegex, urlPlaceholder)
.replace(/(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, '$1@$3');
.replace(validMention, '$1@$3');
}

View file

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

View file

@ -692,6 +692,10 @@ RSpec.describe Account do
expect(subject.match('@alice@example.com')[1]).to eq 'alice@example.com'
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
expect(subject.match('Hello @alice@example.com.')[1]).to eq 'alice@example.com'
end