diff --git a/baked_in.go b/baked_in.go index b6fbaafa..d1a3656a 100644 --- a/baked_in.go +++ b/baked_in.go @@ -1828,7 +1828,14 @@ func requireCheckFieldValue( return int64(field.Len()) == asInt(value) case reflect.Bool: - return field.Bool() == asBool(value) + return field.Bool() == (value == "true") + + case reflect.Ptr: + if field.IsNil() { + return value == "nil" + } + // Handle non-nil pointers + return requireCheckFieldValue(fl, param, value, defaultNotFoundValue) } // default reflect.String: diff --git a/validator_test.go b/validator_test.go index 0f96b777..367a6b41 100644 --- a/validator_test.go +++ b/validator_test.go @@ -12002,6 +12002,25 @@ func TestExcludedIf(t *testing.T) { errs = validate.Struct(test10) Equal(t, errs, nil) + test11 := struct { + Field1 bool + Field2 *string `validate:"excluded_if=Field1 false"` + }{ + Field1: false, + Field2: nil, + } + errs = validate.Struct(test11) + Equal(t, errs, nil) + + test12 := struct { + Field1 bool + Field2 *string `validate:"excluded_if=Field1 !Field1"` + }{ + Field1: true, + Field2: nil, + } + errs = validate.Struct(test12) + Equal(t, errs, nil) // Checks number of params in struct tag is correct defer func() { if r := recover(); r == nil {