mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-22 09:43:47 +00:00
stackitem: ensure map keys are a valid UTF-8
This commit is contained in:
parent
3c99393bef
commit
5500195d58
1 changed files with 10 additions and 2 deletions
|
@ -64,9 +64,17 @@ func toJSON(buf *io.BufBinWriter, item Item) {
|
||||||
case *Map:
|
case *Map:
|
||||||
w.WriteB('{')
|
w.WriteB('{')
|
||||||
for i := range it.value {
|
for i := range it.value {
|
||||||
bs, _ := it.value[i].Key.TryBytes() // map key can always be converted to []byte
|
// map key can always be converted to []byte
|
||||||
|
// but are not always a valid UTF-8.
|
||||||
|
key, err := ToString(it.value[i].Key)
|
||||||
|
if err != nil {
|
||||||
|
if buf.Err == nil {
|
||||||
|
buf.Err = err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
w.WriteB('"')
|
w.WriteB('"')
|
||||||
w.WriteBytes(bs)
|
w.WriteBytes([]byte(key))
|
||||||
w.WriteBytes([]byte(`":`))
|
w.WriteBytes([]byte(`":`))
|
||||||
toJSON(buf, it.value[i].Value)
|
toJSON(buf, it.value[i].Value)
|
||||||
if i < len(it.value)-1 {
|
if i < len(it.value)-1 {
|
||||||
|
|
Loading…
Reference in a new issue