Bladeren bron

fix username validation

Username must contain at least 3 letter characters to be valid. The
rules say that the username must contain at least 3 letters OR numbers.
This commit fixes this.
Mike 1 jaar geleden
bovenliggende
commit
15846bfcc9
2 gewijzigde bestanden met toevoegingen van 2 en 2 verwijderingen
  1. 1 2
      state/user.go
  2. 1 0
      state/user_test.go

+ 1 - 2
state/user.go

@@ -70,10 +70,9 @@ var (
 //   - ErrAIMHandleInvalidFormat: if the screen name does not start with a
 //     letter, ends with a space, or contains invalid characters
 func (s DisplayScreenName) ValidateAIMHandle() error {
-	// Must contain min 3 letters, max 16 letters and spaces.
 	c := 0
 	for _, r := range s {
-		if unicode.IsLetter(r) {
+		if unicode.IsLetter(r) || unicode.IsDigit(r) {
 			c++
 		}
 		if c == 3 {

+ 1 - 0
state/user_test.go

@@ -215,6 +215,7 @@ func TestDisplayScreenName_ValidateAIMHandle(t *testing.T) {
 	}{
 		{"Valid handle no spaces", "User123", nil},
 		{"Valid handle with min character count and space", "U SR", nil},
+		{"Valid handle with min character including letters and numbers", "dj3520", nil},
 		{"Valid handle with max character count", "JustTheRightSize", nil},
 		{"Valid handle with max character count and spaces", "Just   RightSize", nil},
 		{"Too short", "Us", ErrAIMHandleLength},