validator
validator copied to clipboard
required_if panics with ValidateMap on simple map with a single rule
- [ X] I have looked at the documentation here first?
- [ X] I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
required_if panics panic("Invalid field namespace")
when using ValidateMap with simple rules.
Code sample, to showcase or reproduce:
https://go.dev/play/p/6do5LR2UroT
package main
import (
"fmt"
"github.com/go-playground/validator/v10"
)
func main() {
data := map[string]interface{}{
"name": "hello",
"id": 123,
}
rules := map[string]interface{}{
"name": "required_if=id 345",
"id": 123,
}
v := validator.New()
fmt.Println(v.ValidateMap(data, rules))
}
panic: Invalid field namespace
goroutine 1 [running]:
github.com/go-playground/validator/v10.(*validate).getStructFieldOKInternal(0xe55630636d8df4e, {0x538880, 0x595648, 0xc00029f670}, {0x5672a7, 0xc00030a6e0})
/tmp/gopath1590948958/pkg/mod/github.com/go-playground/validator/[email protected]/util.go:220 +0x160b
github.com/go-playground/validator/v10.(*validate).GetStructFieldOKAdvanced2(0x6bc240, {0x538880, 0x595648, 0x6}, {0x5672a7, 0x0})
/tmp/gopath1590948958/pkg/mod/github.com/go-playground/validator/[email protected]/field_level.go:119 +0x28
github.com/go-playground/validator/v10.requireCheckFieldValue({0x59a318, 0xc00007b9e0}, {0x5672a7, 0x2}, {0x5672aa, 0x3}, 0x8)
/tmp/gopath1590948958/pkg/mod/github.com/
this issue has been a long time, any plan fix it and merge into main branch?
+1 i used version 10.15.5 the problem still exists
this is weird... How such a long maintained and popular package has such a bug which hasn't been fixed since 2022? Isn't "required_if" an essential tag?