diff --git a/issues_test.go b/issues_test.go index 7b172d8..c6dd427 100644 --- a/issues_test.go +++ b/issues_test.go @@ -1480,6 +1480,48 @@ func TestIssues_223(t *testing.T) { assert.StrContains(t, s, "clinics.*.doctors.*.duration value must be an integer") } +// issues#246 类似这样的结构体和规则 +type CertStore struct { + Type string `form:"type" json:"type"` + Domains []string `form:"domains" json:"domains"` + AutoRenew bool `form:"auto_renew" json:"auto_renew"` + UserID uint `form:"user_id" json:"user_id" filter:"uint"` + DNSID uint `form:"dns_id" json:"dns_id" filter:"uint"` + WebsiteID uint `form:"website_id" json:"website_id" filter:"uint"` +} + +func (r *CertStore) Rules() map[string]string { + return map[string]string{ + "type": "required|in:P256,P384,2048,4096", + "domains": "required|array", + "auto_renew": "required|bool", + "user_id": "required|uint|exists:cert_users,id", + "dns_id": "uint", + "website_id": "uint", + } +} + +// https://github.com/gookit/validate/issues/246 +// 使用 uint filter时,传 null 值会报错 convert value type error +func TestIssues_246(t *testing.T) { + jsonStr := `{ + "domains": [], + "dns_id": null, + "type": "P256", + "user_id": null, + "website_id": null, + "auto_renew": true +}` + cs := &CertStore{} + err := jsonutil.DecodeString(jsonStr, cs) + assert.NoErr(t, err) + dump.P(cs) + + v := validate.Struct(cs) + assert.True(t, v.Validate()) + dump.P(cs) +} + type mockUUID [16]byte type TestUser struct {