-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
What happened?
Array of integers pass validations for strings.
Tested with all string tags validation.
Go playground with all strings validations tested (they all pass)
https://go.dev/play/p/cky_4b8iONw
Maybe I misinterpreted something, or this is a strange bug?
Version
Tested with 2 versions:
- 10.22.0
- 10.28.0
Example Code
package main
import (
"log"
"github.com/go-playground/validator/v10"
)
func main() {
validate := validator.New(validator.WithRequiredStructEnabled())
arr := []int{3000}
tagsToTest := [...]string{
"alpha",
"alphaspace",
"alphanum",
"alphanumunicode",
"alphaunicode",
"ascii",
"boolean",
"contains",
"containsany",
"containsrune",
"endsnotwith",
"endswith",
"excludes",
"excludesall",
"excludesrune",
"lowercase",
"multibyte",
"number",
"numeric",
"printascii",
"startsnotwith",
"startswith",
"uppercase",
}
for i := range tagsToTest {
tag := tagsToTest[i]
if err := validate.Var(arr, "printascii"); err != nil {
log.Printf("%s: NOT PASSED - %s\n", tag, err.Error())
} else {
log.Printf("%s: PASSED\n", tag)
}
}
}