Skip to content

exclude_with and exclude_without don't work on pointer fields  #745

@Jake-Convictional

Description

@Jake-Convictional

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

Using the exclude_with or exclude_without tags don't work as expected on pointer fields (e.g. *string).

See the example below, where the validation fails even though the "excluded" fields are never included. Change the types from *string to string and now the validation succeeds.

Code sample, to showcase or reproduce:

type Test1 struct {
	Field1 string
	Field2 *string `validate:"excluded_with=Field1"`
}

type Test2 struct {
	Field1 string
	Field2 *string `validate:"excluded_without=Field1"`
}

func main() {
	v := validator.New()
	fmt.Println(v.Struct(&Test1{Field1: "ok"})) // Fails, even though Field2 is null
	fmt.Println(v.Struct(&Test2{Field1: "ok"})) // Fails, even though Field2 is null
}

https://play.golang.org/p/QTjxLJOSF8W

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