From a8fac9b1e2dd07b3cad4bd65086b4602a271b9b7 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Wed, 13 May 2026 20:14:03 +0200 Subject: [PATCH] forgery: safer unique name --- tests/forgery/user.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/forgery/user.go b/tests/forgery/user.go index 1175297497..7190dab9da 100644 --- a/tests/forgery/user.go +++ b/tests/forgery/user.go @@ -7,6 +7,7 @@ import ( "math/rand/v2" "regexp" "strconv" + "strings" "testing" org_model "forgejo.org/models/organization" @@ -19,7 +20,7 @@ var nameCleaner = regexp.MustCompile(`[^a-zA-Z0-9-]+`) // exclude "_", to preven // uniqueSafeName replaces specials chars with _ and appends a random hex suffix func uniqueSafeName(testName string) string { - return nameCleaner.ReplaceAllLiteralString(testName, "_") + "-" + strconv.FormatUint(uint64(rand.Uint32()), 16) + return strings.Trim(nameCleaner.ReplaceAllLiteralString(testName, "_"), "-_") + "-" + strconv.FormatUint(uint64(rand.Uint32()), 16) } type CreateUserOptions struct {