diff --git a/client-sdk/go/config/identifier.go b/client-sdk/go/config/identifier.go index ac555b91cb..f615d731c6 100644 --- a/client-sdk/go/config/identifier.go +++ b/client-sdk/go/config/identifier.go @@ -5,7 +5,7 @@ import ( "regexp" ) -var validID = regexp.MustCompile(`^[a-z0-9_]+$`) +var validID = regexp.MustCompile(`^[a-z0-9][a-z0-9_]*$`) // ValidateIdentifier makes sure the given string is a valid identifier. func ValidateIdentifier(id string) error { @@ -14,8 +14,10 @@ func ValidateIdentifier(id string) error { return fmt.Errorf("identifier cannot be empty") case len(id) > 64: return fmt.Errorf("identifier must be less than 64 characters long") + case id == "default": + return fmt.Errorf("identifier cannot be the string 'default'") case !validID.MatchString(id): - return fmt.Errorf("identifier must only contain lower-case letters, numbers and _") + return fmt.Errorf("identifier must start with a lower-case letter or number and only contain lower-case letters, numbers and _") default: return nil } diff --git a/client-sdk/go/config/identifier_test.go b/client-sdk/go/config/identifier_test.go index f5e3003738..12775a1749 100644 --- a/client-sdk/go/config/identifier_test.go +++ b/client-sdk/go/config/identifier_test.go @@ -20,6 +20,11 @@ func TestValidateIdentifier(t *testing.T) { {"222", true}, {"abc", true}, {"abc_2", true}, + {"_v", false}, + {"_foo", false}, + {"default", false}, + {"a", true}, + {"2", true}, } { if tc.valid { require.NoError(ValidateIdentifier(tc.id), tc.id)