mirror of
https://github.com/mastodon/mastodon.git
synced 2025-07-14 16:28:16 +00:00
Compare commits
6 Commits
23f12fbffb
...
965203a094
Author | SHA1 | Date | |
---|---|---|---|
![]() |
965203a094 | ||
![]() |
a04273b06d | ||
![]() |
efffde0230 | ||
![]() |
fd4c869f63 | ||
![]() |
e7d0e511a9 | ||
![]() |
1b909c98ab |
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user