From 8174f1bc4b6eec954eb3c9277d8994fbe9aaeaf4 Mon Sep 17 00:00:00 2001 From: fgy Date: Tue, 29 Aug 2023 20:21:45 +0800 Subject: [PATCH] fix: interface panic --- binding/bind_test.go | 11 +++++++++++ binding/param_info.go | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/binding/bind_test.go b/binding/bind_test.go index 7501e38..b56ca1b 100644 --- a/binding/bind_test.go +++ b/binding/bind_test.go @@ -1196,3 +1196,14 @@ func TestVdTagRecursion(t *testing.T) { assert.NoError(t, err) assert.Less(t, int64(time.Since(start)), int64(time.Second)) } + +func TestInterface(t *testing.T) { + type foo struct { + F1 interface{} `query:"f1"` + } + recv := &foo{} + req, _ := http.NewRequest("get", "http://localhost/?f1=f1", bytes.NewReader([]byte{})) + binder := binding.New(nil) + err := binder.BindAndValidate(recv, req, nil) + assert.NoError(t, err) +} diff --git a/binding/param_info.go b/binding/param_info.go index 7bbbd04..7730552 100644 --- a/binding/param_info.go +++ b/binding/param_info.go @@ -236,7 +236,9 @@ func (p *paramInfo) bindStringSlice(info *tagInfo, expr *tagexpr.TagExpr, a []st } v = ameda.DereferenceValue(v) - + if !v.IsValid() { + return nil + } // we have customized unmarshal defined, we should use it firstly if fn, exist := typeUnmarshalFuncs[v.Type()]; exist { vv, err := fn(a[0], p.looseZeroMode)