Fix panic when unmarshaling into a map twice (#854)

Fixes #851
This commit is contained in:
Thomas Pelletier
2023-02-28 17:34:24 +01:00
committed by GitHub
parent 8a416daa69
commit 643c251c4b
2 changed files with 16 additions and 7 deletions
+1 -7
View File
@@ -1039,15 +1039,9 @@ func (d *decoder) handleKeyValuePart(key unstable.Iterator, value *unstable.Node
mv := v.MapIndex(mk)
set := false
if !mv.IsValid() {
if !mv.IsValid() || key.IsLast() {
set = true
mv = reflect.New(v.Type().Elem()).Elem()
} else {
if key.IsLast() {
var x interface{}
mv = reflect.ValueOf(&x).Elem()
set = true
}
}
nv, err := d.handleKeyValueInner(key, value, mv)