mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-15 06:01:12 +00:00
Merge a04273b06d
into 8c579c5b34
This commit is contained in:
commit
d1f53b6322
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -431,6 +431,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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user