Fix interface issue when value is set but no validation tag exists

pull/107/head
joeybloggs 9 years ago
parent e02a29b19b
commit e1fd32247f
  1. 2
      validator.go
  2. 13
      validator_test.go

@ -610,7 +610,7 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f
var valueField reflect.Value var valueField reflect.Value
// This is a double check if coming from validate.Struct but need to be here in case function is called directly // This is a double check if coming from validate.Struct but need to be here in case function is called directly
if tag == noValidationTag { if tag == noValidationTag || tag == "" {
return nil return nil
} }

@ -606,6 +606,19 @@ func TestInterfaceErrValidation(t *testing.T) {
Equal(t, err.IsPlaceholderErr, false) Equal(t, err.IsPlaceholderErr, false)
Equal(t, err.IsSliceOrArray, false) Equal(t, err.IsSliceOrArray, false)
Equal(t, len(err.SliceOrArrayErrs), 0) Equal(t, len(err.SliceOrArrayErrs), 0)
type MyStruct struct {
A, B string
C interface{}
}
var a MyStruct
a.A = "value"
a.C = "nu"
errs = validate.Struct(a)
Equal(t, errs, nil)
} }
func TestMapDiveValidation(t *testing.T) { func TestMapDiveValidation(t *testing.T) {

Loading…
Cancel
Save