mirror of https://github.com/goccy/go-json.git
fix: decode struct with pointer must be nil (#473)
This commit is contained in:
parent
3d5ab28ab3
commit
df897aec9d
|
@ -197,6 +197,13 @@ func Test_Decoder(t *testing.T) {
|
|||
assertEq(t, "interface{}", v.F, nil)
|
||||
assertEq(t, "nilfunc", true, v.G == nil)
|
||||
})
|
||||
t.Run("struct.pointer must be nil", func(t *testing.T) {
|
||||
var v struct {
|
||||
A *int
|
||||
}
|
||||
json.Unmarshal([]byte(`{"a": "alpha"}`), &v)
|
||||
assertEq(t, "struct.A", v.A, (*int)(nil))
|
||||
})
|
||||
})
|
||||
t.Run("interface", func(t *testing.T) {
|
||||
t.Run("number", func(t *testing.T) {
|
||||
|
|
|
@ -85,6 +85,7 @@ func (d *ptrDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe.P
|
|||
}
|
||||
c, err := d.dec.Decode(ctx, cursor, depth, newptr)
|
||||
if err != nil {
|
||||
*(*unsafe.Pointer)(p) = nil
|
||||
return 0, err
|
||||
}
|
||||
cursor = c
|
||||
|
|
Loading…
Reference in New Issue