mirror of
https://github.com/mastodon/mastodon.git
synced 2024-06-01 18:32:39 +00:00
Merge 3930f4a29c
into 2da2a1dae9
This commit is contained in:
commit
20b66a81f9
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue