From 84f8b36eae1c52663919040952e8465366d54b4d Mon Sep 17 00:00:00 2001 From: Mischa Holz Date: Sun, 3 Sep 2023 21:46:04 +0200 Subject: [PATCH] Replace the domain part of the mention regex with twitter's validDomain --- .../mastodon/features/compose/util/counter.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/features/compose/util/counter.js b/app/javascript/mastodon/features/compose/util/counter.js index ec2431096b..8ac2f937ee 100644 --- a/app/javascript/mastodon/features/compose/util/counter.js +++ b/app/javascript/mastodon/features/compose/util/counter.js @@ -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'); }