validator icon indicating copy to clipboard operation
validator copied to clipboard

required_if panics with ValidateMap on simple map with a single rule

Open dosco opened this issue 3 years ago • 3 comments

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

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

required_if panics panic("Invalid field namespace") when using ValidateMap with simple rules.

Code sample, to showcase or reproduce:

https://go.dev/play/p/6do5LR2UroT


package main

import (
	"fmt"

	"github.com/go-playground/validator/v10"
)

func main() {
	data := map[string]interface{}{
		"name": "hello",
		"id":   123,
	}

	rules := map[string]interface{}{
		"name": "required_if=id 345",
		"id":   123,
	}

	v := validator.New()
	fmt.Println(v.ValidateMap(data, rules))
}

panic: Invalid field namespace

goroutine 1 [running]:
github.com/go-playground/validator/v10.(*validate).getStructFieldOKInternal(0xe55630636d8df4e, {0x538880, 0x595648, 0xc00029f670}, {0x5672a7, 0xc00030a6e0})
	/tmp/gopath1590948958/pkg/mod/github.com/go-playground/validator/[email protected]/util.go:220 +0x160b
github.com/go-playground/validator/v10.(*validate).GetStructFieldOKAdvanced2(0x6bc240, {0x538880, 0x595648, 0x6}, {0x5672a7, 0x0})
	/tmp/gopath1590948958/pkg/mod/github.com/go-playground/validator/[email protected]/field_level.go:119 +0x28
github.com/go-playground/validator/v10.requireCheckFieldValue({0x59a318, 0xc00007b9e0}, {0x5672a7, 0x2}, {0x5672aa, 0x3}, 0x8)
	/tmp/gopath1590948958/pkg/mod/github.com/

dosco avatar Feb 06 '22 07:02 dosco

this issue has been a long time, any plan fix it and merge into main branch?

cchengubnt avatar Mar 10 '23 10:03 cchengubnt

+1 i used version 10.15.5 the problem still exists

zein-adi avatar Oct 08 '23 08:10 zein-adi

this is weird... How such a long maintained and popular package has such a bug which hasn't been fixed since 2022? Isn't "required_if" an essential tag?

thedenisnikulin avatar Jan 25 '24 08:01 thedenisnikulin