Skip to content

Commit

Permalink
client-sdk/go: Update validity rules for config identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Sep 3, 2023
1 parent a01f864 commit 47803dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client-sdk/go/config/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions client-sdk/go/config/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 47803dc

Please sign in to comment.