stackitem: properly detect recursive references during serialization

If we're done with element it no longer can lead to recursion error, so fix
cases like `[arr, arr]` where we have two copies of `arr` trigger this error
for no good reason (there is no recursion there).
This commit is contained in:
Roman Khimov 2021-07-06 17:10:31 +03:00
parent ae8f4ebd5e
commit 6879cbcdcc
2 changed files with 4 additions and 0 deletions

View file

@ -241,6 +241,7 @@ func toJSONWithTypes(item Item, seen map[Item]bool) (interface{}, error) {
arr = append(arr, s)
}
value = arr
delete(seen, item)
case *Bool:
value = it.value
case *Buffer, *ByteArray:
@ -266,6 +267,7 @@ func toJSONWithTypes(item Item, seen map[Item]bool) (interface{}, error) {
})
}
value = arr
delete(seen, item)
case *Pointer:
value = it.pos
}

View file

@ -82,6 +82,7 @@ func serializeItemTo(item Item, w *io.BinWriter, allowInvalid bool, seen map[Ite
for i := range arr {
serializeItemTo(arr[i], w, allowInvalid, seen)
}
delete(seen, item)
case *Map:
seen[item] = true
@ -91,6 +92,7 @@ func serializeItemTo(item Item, w *io.BinWriter, allowInvalid bool, seen map[Ite
serializeItemTo(t.Value().([]MapElement)[i].Key, w, allowInvalid, seen)
serializeItemTo(t.Value().([]MapElement)[i].Value, w, allowInvalid, seen)
}
delete(seen, item)
case Null:
w.WriteB(byte(AnyT))
}