File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -534,12 +534,20 @@ func hasMultiByteCharacter(fl FieldLevel) bool {
534534
535535// isPrintableASCII is the validation function for validating if the field's value is a valid printable ASCII character.
536536func isPrintableASCII (fl FieldLevel ) bool {
537- return printableASCIIRegex ().MatchString (fl .Field ().String ())
537+ field := fl .Field ()
538+ if field .Kind () == reflect .String {
539+ return printableASCIIRegex ().MatchString (field .String ())
540+ }
541+ return false
538542}
539543
540544// isASCII is the validation function for validating if the field's value is a valid ASCII character.
541545func isASCII (fl FieldLevel ) bool {
542- return aSCIIRegex ().MatchString (fl .Field ().String ())
546+ field := fl .Field ()
547+ if field .Kind () == reflect .String {
548+ return aSCIIRegex ().MatchString (field .String ())
549+ }
550+ return false
543551}
544552
545553// isUUID5 is the validation function for validating if the field's value is a valid v5 UUID.
Original file line number Diff line number Diff line change @@ -3904,7 +3904,7 @@ func TestMultibyteValidation(t *testing.T) {
39043904
39053905func TestPrintableASCIIValidation (t * testing.T ) {
39063906 tests := []struct {
3907- param string
3907+ param interface {}
39083908 expected bool
39093909 }{
39103910 {"" , true },
@@ -3918,6 +3918,8 @@ func TestPrintableASCIIValidation(t *testing.T) {
39183918 {"1234abcDEF" , true },
39193919 {"newline\n " , false },
39203920 {"\x19 test\x7F " , false },
3921+ {[]int {3000 }, false },
3922+ {1 , false },
39213923 }
39223924
39233925 validate := New ()
@@ -3944,7 +3946,7 @@ func TestPrintableASCIIValidation(t *testing.T) {
39443946
39453947func TestASCIIValidation (t * testing.T ) {
39463948 tests := []struct {
3947- param string
3949+ param interface {}
39483950 expected bool
39493951 }{
39503952 {"" , true },
@@ -3957,6 +3959,8 @@ func TestASCIIValidation(t *testing.T) {
3957395939583960 {"1234abcDEF" , true },
39593961 {"" , true },
3962+ {[]int {3000 }, false },
3963+ {1 , false },
39603964 }
39613965
39623966 validate := New ()
You can’t perform that action at this time.
0 commit comments