From 9e58bcdee1beffe9bc154650ab80f5f055ff74af Mon Sep 17 00:00:00 2001 From: Pantelis Sampaziotis Date: Fri, 7 Feb 2020 16:30:58 +0200 Subject: [PATCH] Empty strings are not lowercase or uppercase --- baked_in.go | 6 ++++++ validator_test.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/baked_in.go b/baked_in.go index 57440cb..91fd479 100644 --- a/baked_in.go +++ b/baked_in.go @@ -2015,6 +2015,9 @@ func isLowercase(fl FieldLevel) bool { field := fl.Field() if field.Kind() == reflect.String { + if field.String() == "" { + return false + } return field.String() == strings.ToLower(field.String()) } @@ -2026,6 +2029,9 @@ func isUppercase(fl FieldLevel) bool { field := fl.Field() if field.Kind() == reflect.String { + if field.String() == "" { + return false + } return field.String() == strings.ToUpper(field.String()) } diff --git a/validator_test.go b/validator_test.go index 1114071..f5d6d01 100644 --- a/validator_test.go +++ b/validator_test.go @@ -9011,7 +9011,7 @@ func TestLowercaseValidation(t *testing.T) { }{ {`abcdefg`, true}, {`Abcdefg`, false}, - {"", true}, + {"", false}, } validate := New() @@ -9048,7 +9048,7 @@ func TestUppercaseValidation(t *testing.T) { }{ {`ABCDEFG`, true}, {`aBCDEFG`, false}, - {"", true}, + {"", false}, } validate := New()