Skip to content

Commit 2306624

Browse files
committed
fix: Judge invalid value
Change-Id: Ib8fd49c14b04f49df893bc6fe56545434ddf5859
1 parent a67041b commit 2306624

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tagexpr.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ func (vm *VM) RunAny(v interface{}, fn func(*TagExpr, error) error) error {
146146

147147
func (vm *VM) subRunAll(omitNil bool, tePath string, value reflect.Value, fn func(*TagExpr, error) error) error {
148148
rv := goutil.DereferenceIfaceValue(value)
149+
if !rv.IsValid() {
150+
return nil
151+
}
149152
rt := goutil.DereferenceType(rv.Type())
150153
rv = goutil.DereferenceValue(rv)
151154
switch rt.Kind() {

validator/validator_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAll(t *testing.T) {
2626
assert.EqualError(t, vd.Validate(new(T), true), "invalid parameter: a\tinvalid parameter: f.g")
2727
}
2828

29-
func TestIssue(t *testing.T) {
29+
func TestIssue1(t *testing.T) {
3030
type MailBox struct {
3131
Address *string `vd:"email($)"`
3232
Name *string
@@ -67,3 +67,17 @@ func TestIssue(t *testing.T) {
6767
}
6868
assert.EqualError(t, vd.Validate(req, true), "invalid parameter: Msg.Recipients[0].Address")
6969
}
70+
71+
func TestIssue2(t *testing.T) {
72+
type a struct {
73+
m map[string]interface{}
74+
}
75+
A := &a{
76+
m: map[string]interface{}{
77+
"1": 1,
78+
"2": nil,
79+
},
80+
}
81+
v := vd.New("vd")
82+
assert.NoError(t, v.Validate(A))
83+
}

0 commit comments

Comments
 (0)