Empty strings are not lowercase or uppercase

pull/572/head
Pantelis Sampaziotis 5 years ago
parent 5b51bff4e6
commit 9e58bcdee1
  1. 6
      baked_in.go
  2. 4
      validator_test.go

@ -2015,6 +2015,9 @@ func isLowercase(fl FieldLevel) bool {
field := fl.Field() field := fl.Field()
if field.Kind() == reflect.String { if field.Kind() == reflect.String {
if field.String() == "" {
return false
}
return field.String() == strings.ToLower(field.String()) return field.String() == strings.ToLower(field.String())
} }
@ -2026,6 +2029,9 @@ func isUppercase(fl FieldLevel) bool {
field := fl.Field() field := fl.Field()
if field.Kind() == reflect.String { if field.Kind() == reflect.String {
if field.String() == "" {
return false
}
return field.String() == strings.ToUpper(field.String()) return field.String() == strings.ToUpper(field.String())
} }

@ -9011,7 +9011,7 @@ func TestLowercaseValidation(t *testing.T) {
}{ }{
{`abcdefg`, true}, {`abcdefg`, true},
{`Abcdefg`, false}, {`Abcdefg`, false},
{"", true}, {"", false},
} }
validate := New() validate := New()
@ -9048,7 +9048,7 @@ func TestUppercaseValidation(t *testing.T) {
}{ }{
{`ABCDEFG`, true}, {`ABCDEFG`, true},
{`aBCDEFG`, false}, {`aBCDEFG`, false},
{"", true}, {"", false},
} }
validate := New() validate := New()

Loading…
Cancel
Save