From 1a3715a039404b4a4b6c856bfe5e83b4c3fc2f2b Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Wed, 17 Jul 2024 13:12:45 +0200 Subject: [PATCH 1/2] Fixed job name normalisation for bundle generate --- libs/textutil/textutil.go | 10 +++++++++- libs/textutil/textutil_test.go | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/textutil/textutil.go b/libs/textutil/textutil.go index a5d17d55f5..ee9b0f0f1c 100644 --- a/libs/textutil/textutil.go +++ b/libs/textutil/textutil.go @@ -1,6 +1,7 @@ package textutil import ( + "regexp" "strings" "unicode" ) @@ -9,7 +10,14 @@ import ( // including spaces and dots, which are not supported in e.g. experiment names or YAML keys. func NormalizeString(name string) string { name = strings.ToLower(name) - return strings.Map(replaceNonAlphanumeric, name) + s := strings.Map(replaceNonAlphanumeric, name) + + // replacing multiple underscores with a single one + re := regexp.MustCompile(`_+`) + s = re.ReplaceAllString(s, "_") + + // removing leading and trailing underscores + return strings.Trim(s, "_") } func replaceNonAlphanumeric(r rune) rune { diff --git a/libs/textutil/textutil_test.go b/libs/textutil/textutil_test.go index fb8bf0b608..f6834a1ef3 100644 --- a/libs/textutil/textutil_test.go +++ b/libs/textutil/textutil_test.go @@ -46,6 +46,10 @@ func TestNormalizeString(t *testing.T) { { input: "TestTestTest", expected: "testtesttest", + }, + { + input: ".test//test..test", + expected: "test_test_test", }} for _, c := range cases { From a3a4c69518385e514cd29c9eea598196551b7cd2 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Wed, 17 Jul 2024 14:20:33 +0200 Subject: [PATCH 2/2] update test --- libs/auth/user_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/auth/user_test.go b/libs/auth/user_test.go index eb579fc988..62b2d29ac6 100644 --- a/libs/auth/user_test.go +++ b/libs/auth/user_test.go @@ -22,7 +22,7 @@ func TestGetShortUserName(t *testing.T) { }, { email: "test$.user@example.com", - expected: "test__user", + expected: "test_user", }, { email: `jöhn.dœ@domain.com`, // Using non-ASCII characters. @@ -38,7 +38,7 @@ func TestGetShortUserName(t *testing.T) { }, { email: `"_quoted"@domain.com`, // Quoted strings can be part of the local-part. - expected: "__quoted_", + expected: "quoted", }, { email: `name-o'mally@website.org`, // Single quote in the local-part.