Skip to content

无法验证 url.query 中包含数组的情况 #286

@hwbrzzl

Description

@hwbrzzl

System (please complete the following information):

  • OS: macOS
  • GO Version: 1.23
  • Pkg Version: 1.5.4

Describe the bug

请求连接:/a?date=2023-03&date=2023-04 中包含数组时,无法进行正常校验。

To Reproduce

// 模拟 FromURLValues
v := validate.New(map[string][]string{
	"date": {"2023-03", "2023-04"},
})

v.StringRule("date", "required|array|len:2")
v.StringRule("date.*", "required|date")

if v.Validate() {
	fmt.Println(v.SafeData())
} else {
	fmt.Println(v.Errors)
}

Print:

date:
 len: date field did not pass validation
 array: date value must be an array
date.*:
 required: date.* is required to not be empty

Expected behavior

可以根据代码中规则正常通过校验。

Additional context

问题代码:https://github.com/gookit/validate/blob/master/data_source.go#L845

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions