Skip to content

Commit 988489d

Browse files
Dean KarnDean Karn
authored andcommitted
Merge pull request #108 from joeybloggs/v5-development
V5 development
2 parents 28b71ba + 9d2b8ee commit 988489d

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Package validator
22
================
3+
4+
[![Join the chat at https://gitter.im/bluesuncorp/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bluesuncorp/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
35
[![Build Status](https://travis-ci.org/bluesuncorp/validator.svg?branch=v5.1)](https://travis-ci.org/bluesuncorp/validator)
46
[![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v5)](https://coveralls.io/r/bluesuncorp/validator?branch=v5)
57
[![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v5?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v5)
@@ -127,11 +129,11 @@ Benchmarks
127129
```go
128130
$ go test -cpu=4 -bench=. -benchmem=true
129131
PASS
130-
BenchmarkValidateField-4 3000000 436 ns/op 192 B/op 2 allocs/op
131-
BenchmarkValidateStructSimple-4 500000 2863 ns/op 784 B/op 13 allocs/op
132-
BenchmarkTemplateParallelSimple-4 500000 3044 ns/op 784 B/op 13 allocs/op
133-
BenchmarkValidateStructLarge-4 100000 15226 ns/op 4853 B/op 74 allocs/op
134-
BenchmarkTemplateParallelLarge-4 100000 14637 ns/op 4856 B/op 74 allocs/op
132+
BenchmarkValidateField-4 3000000 429 ns/op 192 B/op 2 allocs/op
133+
BenchmarkValidateStructSimple-4 500000 2877 ns/op 657 B/op 10 allocs/op
134+
BenchmarkTemplateParallelSimple-4 500000 3097 ns/op 657 B/op 10 allocs/op
135+
BenchmarkValidateStructLarge-4 100000 15228 ns/op 4350 B/op 62 allocs/op
136+
BenchmarkTemplateParallelLarge-4 100000 14257 ns/op 4354 B/op 62 allocs/op
135137
```
136138

137139
How to Contribute

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)