Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,20 @@ func hasMultiByteCharacter(fl FieldLevel) bool {

// isPrintableASCII is the validation function for validating if the field's value is a valid printable ASCII character.
func isPrintableASCII(fl FieldLevel) bool {
return printableASCIIRegex().MatchString(fl.Field().String())
field := fl.Field()
if field.Kind() == reflect.String {
return printableASCIIRegex().MatchString(field.String())
}
panic(fmt.Sprintf("Bad field type %s", field.Type()))
}

// isASCII is the validation function for validating if the field's value is a valid ASCII character.
func isASCII(fl FieldLevel) bool {
return aSCIIRegex().MatchString(fl.Field().String())
field := fl.Field()
if field.Kind() == reflect.String {
return aSCIIRegex().MatchString(field.String())
}
panic(fmt.Sprintf("Bad field type %s", field.Type()))
}

// isUUID5 is the validation function for validating if the field's value is a valid v5 UUID.
Expand Down
4 changes: 4 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3940,6 +3940,8 @@ func TestPrintableASCIIValidation(t *testing.T) {
}
}
}
PanicMatches(t, func() { _ = validate.Var([]int{3000}, "printascii") }, "Bad field type []int")
PanicMatches(t, func() { _ = validate.Var(1, "printascii") }, "Bad field type int")
}

func TestASCIIValidation(t *testing.T) {
Expand Down Expand Up @@ -3979,6 +3981,8 @@ func TestASCIIValidation(t *testing.T) {
}
}
}
PanicMatches(t, func() { _ = validate.Var([]int{3000}, "ascii") }, "Bad field type []int")
PanicMatches(t, func() { _ = validate.Var(1, "ascii") }, "Bad field type int")
}

func TestUUID5Validation(t *testing.T) {
Expand Down