diff --git a/README.md b/README.md index e960c23..0734393 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Package validator ================ [![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -![Project status](https://img.shields.io/badge/version-9.1.0-green.svg) +![Project status](https://img.shields.io/badge/version-9.1.1-green.svg) [![Build Status](https://semaphoreci.com/api/v1/joeybloggs/validator/branches/v9/badge.svg)](https://semaphoreci.com/joeybloggs/validator) [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=v9&service=github)](https://coveralls.io/github/go-playground/validator?branch=v9) [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator) diff --git a/translations/en/en.go b/translations/en/en.go index bc6b3ac..1c8c2fe 100644 --- a/translations/en/en.go +++ b/translations/en/en.go @@ -1247,6 +1247,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er translation: "{0} must contain a valid MAC address", override: false, }, + { + tag: "iscolor", + translation: "{0} must be a valid color", + override: false, + }, } for _, t := range translations { diff --git a/translations/en/en_test.go b/translations/en/en_test.go index 05453fe..4203335 100644 --- a/translations/en/en_test.go +++ b/translations/en/en_test.go @@ -128,6 +128,7 @@ func TestTranslations(t *testing.T) { IPAddrv6 string `validate:"ip6_addr"` UinxAddr string `validate:"unix_addr"` // can't fail from within Go's net package currently, but maybe in the future MAC string `validate:"mac"` + IsColor string `validate:"iscolor"` } var test Test @@ -180,6 +181,10 @@ func TestTranslations(t *testing.T) { ns string expected string }{ + { + ns: "Test.IsColor", + expected: "IsColor must be a valid color", + }, { ns: "Test.MAC", expected: "MAC must contain a valid MAC address", diff --git a/validator.go b/validator.go index 6622b98..d9f2f17 100644 --- a/validator.go +++ b/validator.go @@ -310,6 +310,11 @@ OUTER: v.misc = append(v.misc, '|') v.misc = append(v.misc, ct.tag...) + if len(ct.param) > 0 { + v.misc = append(v.misc, '=') + v.misc = append(v.misc, ct.param...) + } + if ct.next == nil || ct.next.typeof != typeOr { // ct.typeof != typeOr // if we get here, no valid 'or' value and no more tags @@ -373,6 +378,10 @@ OUTER: v.flField = current v.flParam = ct.param + // // report error interface functions need these + // v.ns = ns + // v.actualNs = structNs + if !ct.fn(v) { v.str1 = string(append(ns, cf.altName...)) diff --git a/validator_test.go b/validator_test.go index daa166c..89f5ab8 100644 --- a/validator_test.go +++ b/validator_test.go @@ -5504,7 +5504,7 @@ func TestOrTag(t *testing.T) { s = "this ain't right" errs = validate.Var(s, "rgb|rgba|len=10") NotEqual(t, errs, nil) - AssertError(t, errs, "", "", "", "", "rgb|rgba|len") + AssertError(t, errs, "", "", "", "", "rgb|rgba|len=10") s = "this is right" errs = validate.Var(s, "rgb|rgba|len=13")