Skip to content

required_without rule results in panic or error when validateMap is used #943

@benjamin-eich-publicare

Description

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10 (v10.11.0)

Issue, Question or Enhancement:

There seems to be a problem with the required_without validation. It might also affect other rules that validate a field against other fields.

Please see the code examples below for expected and observed behavior.

If more information is needed I'm happy to provide it. Thanks for your help!

Code sample, to showcase or reproduce:

Example 1

v := validator.New()

dataMap := map[string]interface{}{
    "foo": "bar",
    "foo2": "",
}
validationRules := map[string]interface{}{
    "foo": "required_without=foo2",
}
res := v.ValidateMap(dataMap, validationRules)

results in

panic: Invalid field namespace

Expected result would be an empty res because everything is fine.

Example 2

v := validator.New()

dataMap := map[string]interface{}{
//    "foo": "",
    "foo2": "bar",
}
validationRules := map[string]interface{}{
    "foo": "required_without=foo2",
}
res := v.ValidateMap(dataMap, validationRules)

fmt.Printf("%+v\n", res)

results in (no difference if foo is provided or not)

map[foo:Key: '' Error:Field validation for '' failed on the 'required_without' tag]

Expected result would be an empty res because everything is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions