Skip to content

Commit 8174f1b

Browse files
committed
fix: interface panic
1 parent 8355f4a commit 8174f1b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

binding/bind_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,14 @@ func TestVdTagRecursion(t *testing.T) {
11961196
assert.NoError(t, err)
11971197
assert.Less(t, int64(time.Since(start)), int64(time.Second))
11981198
}
1199+
1200+
func TestInterface(t *testing.T) {
1201+
type foo struct {
1202+
F1 interface{} `query:"f1"`
1203+
}
1204+
recv := &foo{}
1205+
req, _ := http.NewRequest("get", "http://localhost/?f1=f1", bytes.NewReader([]byte{}))
1206+
binder := binding.New(nil)
1207+
err := binder.BindAndValidate(recv, req, nil)
1208+
assert.NoError(t, err)
1209+
}

binding/param_info.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ func (p *paramInfo) bindStringSlice(info *tagInfo, expr *tagexpr.TagExpr, a []st
236236
}
237237

238238
v = ameda.DereferenceValue(v)
239-
239+
if !v.IsValid() {
240+
return nil
241+
}
240242
// we have customized unmarshal defined, we should use it firstly
241243
if fn, exist := typeUnmarshalFuncs[v.Type()]; exist {
242244
vv, err := fn(a[0], p.looseZeroMode)

0 commit comments

Comments
 (0)