From e1fd32247fdca4ef85661aed75b1d5fbd2bb92ba Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Thu, 9 Jul 2015 14:06:48 -0400 Subject: [PATCH] Fix interface issue when value is set but no validation tag exists --- validator.go | 2 +- validator_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/validator.go b/validator.go index b2ccb95..ccd2a55 100644 --- a/validator.go +++ b/validator.go @@ -610,7 +610,7 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f 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 - if tag == noValidationTag { + if tag == noValidationTag || tag == "" { return nil } diff --git a/validator_test.go b/validator_test.go index da195dc..1b2e803 100644 --- a/validator_test.go +++ b/validator_test.go @@ -606,6 +606,19 @@ func TestInterfaceErrValidation(t *testing.T) { Equal(t, err.IsPlaceholderErr, false) Equal(t, err.IsSliceOrArray, false) 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) {