From 108efac91879a3b3e6b916b8bc0ee3ca4d1eb8e4 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Thu, 24 Oct 2024 07:56:58 -0600 Subject: [PATCH] =?UTF-8?q?Revert=20"MM-54502=20-=20Update=20regex=20to=20?= =?UTF-8?q?force=20first=20character=20to=20be=20alpha=20=E2=80=A6=20(#288?= =?UTF-8?q?60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revert "MM-54502 - Update regex to force first character to be alpha (#24675)" This reverts commit 08ed72f0601c26d6ee2e298f2f7455c5f5b73544. * update tests for reverted PR * Revert "update tests for reverted PR" This reverts commit c1cf5495fa129008e44a8fcdc0ee34762b33dd34. * Revert "Revert "MM-54502 - Update regex to force first character to be alpha (#24675)"" This reverts commit 6920b979c8dba86a837bafff7c057dc609c6aa58. * only revert important parts, not tests --------- Co-authored-by: Mattermost Build --- server/public/model/user.go | 5 ++--- server/public/model/user_test.go | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/server/public/model/user.go b/server/public/model/user.go index b01e667c5d..4bbe1808d3 100644 --- a/server/public/model/user.go +++ b/server/public/model/user.go @@ -976,8 +976,7 @@ func HashPassword(password string) (string, error) { } var validUsernameChars = regexp.MustCompile(`^[a-z0-9\.\-_]+$`) -var validUsername = regexp.MustCompile(`^[a-z][a-z0-9\.\-_]*$`) -var validUsernameCharsForRemote = regexp.MustCompile(`^[a-z][a-z0-9\.\-_:]*$`) +var validUsernameCharsForRemote = regexp.MustCompile(`^[a-z0-9\.\-_:]*$`) var restrictedUsernames = map[string]struct{}{ "all": {}, @@ -991,7 +990,7 @@ func IsValidUsername(s string) bool { return false } - if !validUsername.MatchString(s) { + if !validUsernameChars.MatchString(s) { return false } diff --git a/server/public/model/user_test.go b/server/public/model/user_test.go index 927b8f2242..b870a7018c 100644 --- a/server/public/model/user_test.go +++ b/server/public/model/user_test.go @@ -431,9 +431,9 @@ var usernames = []usernamesTest{ {"spin-punch", true, true}, {"sp", true, true}, {"s", true, true}, - {"1spin-punch", false, false}, - {"-spin-punch", false, false}, - {".spin-punch", false, false}, + {"1spin-punch", true, true}, + {"-spin-punch", true, true}, + {".spin-punch", true, true}, {"Spin-punch", false, false}, {"spin punch-", false, false}, {"spin_punch", true, true},