Merge pull request #484 from leafduo/v9

Make `required_without` work with pointer
updates-and-fixes
Dean Karn 5 years ago committed by GitHub
commit d6546ee64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      baked_in.go
  2. 2
      validator_test.go

@ -1308,8 +1308,12 @@ func hasValue(fl FieldLevel) bool {
func requireCheckFieldKind(fl FieldLevel, param string) bool { func requireCheckFieldKind(fl FieldLevel, param string) bool {
field := fl.Field() field := fl.Field()
if len(param) > 0 { if len(param) > 0 {
if fl.Parent().Kind() == reflect.Ptr {
field = fl.Parent().Elem().FieldByName(param)
} else {
field = fl.Parent().FieldByName(param) field = fl.Parent().FieldByName(param)
} }
}
switch field.Kind() { switch field.Kind() {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func: case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
return !field.IsNil() return !field.IsNil()

@ -8712,7 +8712,7 @@ func TestRequiredWithout(t *testing.T) {
Field5: "test", Field5: "test",
} }
errs = validate.Struct(test2) errs = validate.Struct(&test2)
if errs == nil { if errs == nil {
t.Fatalf("failed Error: %s", errs) t.Fatalf("failed Error: %s", errs)

Loading…
Cancel
Save