Skip to content

Commit e1fd322

Browse files
joeybloggsjoeybloggs
authored andcommitted
Fix interface issue when value is set but no validation tag exists
1 parent e02a29b commit e1fd322

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ func TestInterfaceErrValidation(t *testing.T) {
606606
Equal(t, err.IsPlaceholderErr, false)
607607
Equal(t, err.IsSliceOrArray, false)
608608
Equal(t, len(err.SliceOrArrayErrs), 0)
609+
610+
type MyStruct struct {
611+
A, B string
612+
C interface{}
613+
}
614+
615+
var a MyStruct
616+
617+
a.A = "value"
618+
a.C = "nu"
619+
620+
errs = validate.Struct(a)
621+
Equal(t, errs, nil)
609622
}
610623

611624
func TestMapDiveValidation(t *testing.T) {

0 commit comments

Comments
 (0)