From 35a0a924830d84f9ec28c129ec85cb1f45011fb8 Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Wed, 3 Aug 2022 10:03:56 +0200
Subject: Use same mastodon regex for usernames

---
 server/helpers/custom-validators/users.ts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'server/helpers')

diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts
index b04970108..8a6f6fca1 100644
--- a/server/helpers/custom-validators/users.ts
+++ b/server/helpers/custom-validators/users.ts
@@ -27,9 +27,9 @@ function isUserVideoQuotaDailyValid (value: string) {
 }
 
 function isUserUsernameValid (value: string) {
-  const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
-  const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
-  return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`))
+  return exists(value) &&
+    validator.matches(value, new RegExp(`^[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?$`)) &&
+    validator.isLength(value, USERS_CONSTRAINTS_FIELDS.USERNAME)
 }
 
 function isUserDisplayNameValid (value: string) {
-- 
cgit v1.2.3