go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.79k stars 1.32k forks source link

`excluded_unless` does not behave as expected #1063

Closed jenoudet closed 1 year ago

jenoudet commented 1 year ago

Relates to #938

Package version:

v10

Issue, Question or Enhancement:

Validator excluded_unless does not behave as the documentation describes. The documentation says: "The field under validation must not be present or is empty unless all the other specified fields are equal to the value following with the specified field." What the validator does: "The field under validation must not be present or is empty if all the other specified fields are equal to the value following with the specified field."

Code sample, to showcase or reproduce:

type Testing struct {
    A string
    B string `validate:"excluded_unless=A include"`
}

errs = validate.Struct(Testing{A: "include", B: "pass"}) // -> Should pass, but fails
errs = validate.Struct(Testing{A: "exclude", B: "fail"}) // -> Should fail, but passes