]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Use same mastodon regex for usernames
authorChocobozzz <me@florianbigard.com>
Wed, 3 Aug 2022 08:03:56 +0000 (10:03 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 3 Aug 2022 08:09:29 +0000 (10:09 +0200)
server/helpers/custom-validators/users.ts

index b04970108ef5171174af2509d2ba36b63f2959c0..8a6f6fca121c133eb4db5da5a2678b57660198dd 100644 (file)
@@ -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) {