From 1bd66b09e38c669c7227b430b8fb689c7b08ac84 Mon Sep 17 00:00:00 2001 From: Jean-Francois Weber-Marx Date: Thu, 24 Jul 2025 01:54:54 +0000 Subject: [PATCH] enhance: allow '.' and '-' characters in usernames (#42417) (#42588) related: #42417 - update the isValidUsername function to accept dots and hyphens in addition to letters, digits, and underscores - this change improves compatibility with common username formats and addresses feedback in issue #42417 Signed-off-by: Jean-Francois Weber-Marx Signed-off-by: Jean-Francois Weber-Marx --- internal/proxy/util.go | 4 ++-- internal/proxy/util_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/proxy/util.go b/internal/proxy/util.go index 3f260f87f4..ec63228a93 100644 --- a/internal/proxy/util.go +++ b/internal/proxy/util.go @@ -1168,8 +1168,8 @@ func ValidateUsername(username string) error { usernameSize := len(username) for i := 1; i < usernameSize; i++ { c := username[i] - if c != '_' && !isAlpha(c) && !isNumber(c) { - return merr.WrapErrParameterInvalidMsg("invalid user name %s, username must contain only numbers, letters and underscores, but got %s", username, c) + if c != '_' && c != '-' && c != '.' && !isAlpha(c) && !isNumber(c) { + return merr.WrapErrParameterInvalidMsg("invalid user name %s, username must contain only numbers, letters, underscores, dots, and hyphens, but got %s", username, c) } } return nil diff --git a/internal/proxy/util_test.go b/internal/proxy/util_test.go index 3ca0c1c654..d7921a7aab 100644 --- a/internal/proxy/util_test.go +++ b/internal/proxy/util_test.go @@ -791,11 +791,11 @@ func TestValidateUsername(t *testing.T) { // length gt 32 res = ValidateUsername("aaaaaaaaaabbbbbbbbbbccccccccccddddd") assert.Error(t, res) - // illegal character which not alphabet, _, or number - res = ValidateUsername("a1^7*).,") + // illegal character which not alphabet, _, ., ., or number + res = ValidateUsername("a1^7*),") assert.Error(t, res) - // normal username that only contains alphabet, _, and number - res = ValidateUsername("a17_good") + // normal username that only contains alphabet, _, ., -, and number + res = ValidateUsername("a.17_good-") assert.Nil(t, res) }