mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-07 20:26:15 +00:00
Merge a04273b06d
into fbe9728f36
This commit is contained in:
commit
a1948c9ea0
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ class Account < ApplicationRecord
|
|||
INSTANCE_ACTOR_ID = -99
|
||||
|
||||
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?)://[^/]+}
|
||||
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
|
||||
USERNAME_LENGTH_LIMIT = 30
|
||||
|
|
|
@ -431,6 +431,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 New Issue
Block a user