Skip to content

Commit

Permalink
fix: interface panic
Browse files Browse the repository at this point in the history
  • Loading branch information
FGYFFFF committed Aug 29, 2023
1 parent 8355f4a commit 8174f1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions binding/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 3 additions & 1 deletion binding/param_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8174f1b

Please sign in to comment.