System (please complete the following information):
- OS:
macOS [e.g. linux, macOS]
- GO Version:
1.25.0 [e.g. 1.13]
- Pkg Version:
1.5.7 [e.g. 1.1.1]
Describe the bug
requiredIf validator does not support pointer values
To Reproduce
package main
import (
"fmt"
"github.com/gookit/validate"
)
type Person struct {
IsOld *bool
Experience *string `validate:"requiredIf:IsOld,true"`
}
func main() {
t := true
e := ""
v1 := Person{
IsOld: &t,
Experience: &e,
}
val := validate.Struct(&v1)
val.Validate()
fmt.Println(val.IsSuccess())
fmt.Println(v1.Experience)
v2 := Person{
IsOld: &t,
}
val = validate.Struct(&v2)
val.Validate()
fmt.Println(val.IsSuccess())
fmt.Println(v2.Experience)
}
Expected behavior
Since for v1 Experience is empty should return false on IsSuccess() call. In case of v2 Experience is nil and IsSuccess() should return false too.
Screenshots
Additional context
Giving it a check I found the problem is in goutil@v0.7.4/reflects/conv.go::L91 on ConvToKind() function. This is called by Validation method RequiredIf. Since does ConvToKind() function does not support pointers by default returns a true validation
System (please complete the following information):
macOS[e.g. linux, macOS]1.25.0[e.g.1.13]1.5.7[e.g.1.1.1]Describe the bug
requiredIf validator does not support pointer values
To Reproduce
Expected behavior
Since for v1 Experience is empty should return false on IsSuccess() call. In case of v2 Experience is nil and IsSuccess() should return false too.
Screenshots
Additional context
Giving it a check I found the problem is in goutil@v0.7.4/reflects/conv.go::L91 on ConvToKind() function. This is called by Validation method RequiredIf. Since does ConvToKind() function does not support pointers by default returns a true validation