Skip to content

Commit

Permalink
Improve validation of pointer fields (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaptinlin committed Sep 19, 2023
1 parent 82b2c54 commit b4d96df
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ func (r *Rule) valueValidate(field, name string, val any, v *Validation) (ok boo

// convert input field value type, is validator func first argument.
func convValAsFuncArg0Type(arg0Kind, valKind reflect.Kind, val any) (any, bool) {
// If the validator function does not expect a pointer, but the value is a pointer,
// dereference the value.
if arg0Kind != reflect.Ptr && valKind == reflect.Ptr {
if val == nil {
return nil, true
}

val = reflect.ValueOf(val).Elem().Interface()
valKind = reflect.TypeOf(val).Kind()
}

// ak, err := basicKind(rftVal)
bk, err := basicKindV2(valKind)
if err != nil {
Expand Down

0 comments on commit b4d96df

Please sign in to comment.