Skip to content

Commit 06aac46

Browse files
Dean KarnDean Karn
authored andcommitted
Merge pull request #109 from bluesuncorp/v5-development
Merge latet changes into v5
2 parents e02a29b + 988489d commit 06aac46

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f
610610
var valueField reflect.Value
611611

612612
// This is a double check if coming from validate.Struct but need to be here in case function is called directly
613-
if tag == noValidationTag {
613+
if tag == noValidationTag || tag == "" {
614614
return nil
615615
}
616616

validator_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ func AssertMapFieldError(t *testing.T, s map[string]*FieldError, field string, e
231231
EqualSkip(t, 2, val.Tag, expectedTag)
232232
}
233233

234+
func TestBadKeyValidation(t *testing.T) {
235+
type Test struct {
236+
Name string `validate:"required, "`
237+
}
238+
239+
tst := &Test{
240+
Name: "test",
241+
}
242+
243+
PanicMatches(t, func() { validate.Struct(tst) }, "Invalid validation tag on field Name")
244+
}
245+
234246
func TestFlattenValidation(t *testing.T) {
235247

236248
type Inner struct {
@@ -606,13 +618,29 @@ func TestInterfaceErrValidation(t *testing.T) {
606618
Equal(t, err.IsPlaceholderErr, false)
607619
Equal(t, err.IsSliceOrArray, false)
608620
Equal(t, len(err.SliceOrArrayErrs), 0)
621+
622+
type MyStruct struct {
623+
A, B string
624+
C interface{}
625+
}
626+
627+
var a MyStruct
628+
629+
a.A = "value"
630+
a.C = "nu"
631+
632+
errs = validate.Struct(a)
633+
Equal(t, errs, nil)
609634
}
610635

611636
func TestMapDiveValidation(t *testing.T) {
612637

638+
n := map[int]interface{}{0: nil}
639+
err := validate.Field(n, "omitempty,required")
640+
613641
m := map[int]string{0: "ok", 3: "", 4: "ok"}
614642

615-
err := validate.Field(m, "len=3,dive,required")
643+
err = validate.Field(m, "len=3,dive,required")
616644
NotEqual(t, err, nil)
617645
Equal(t, err.IsPlaceholderErr, true)
618646
Equal(t, err.IsMap, true)

0 commit comments

Comments
 (0)