Fix the issue of snbt decoding when TagList in TagCompound in TagList

This commit is contained in:
Tnze
2023-04-24 01:29:20 +08:00
parent cbf5a7c053
commit de254fb1c6
2 changed files with 13 additions and 0 deletions

View File

@ -254,6 +254,12 @@ func writeListOrArray(e *Encoder, d *decodeState, writeTag bool, tagName string)
return tagType, err return tagType, err
} }
case scanBeginList: // TAG_List<TAG_List> case scanBeginList: // TAG_List<TAG_List>
if writeTag {
err = e.writeTag(TagList, tagName)
if err != nil {
return tagType, err
}
}
var elemType byte var elemType byte
for { for {
if d.opcode == scanSkipSpace { if d.opcode == scanSkipSpace {
@ -291,6 +297,12 @@ func writeListOrArray(e *Encoder, d *decodeState, writeTag bool, tagName string)
return return
} }
case scanBeginCompound: // TAG_List<TAG_Compound> case scanBeginCompound: // TAG_List<TAG_Compound>
if writeTag {
err = e.writeTag(TagList, tagName)
if err != nil {
return tagType, err
}
}
for { for {
if d.opcode == scanSkipSpace { if d.opcode == scanSkipSpace {
d.scanWhile(scanSkipSpace) d.scanWhile(scanSkipSpace)

View File

@ -50,6 +50,7 @@ var testCases = []testCase{
{`{d:[]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'd', 0, 0, 0, 0, 0, 0}}, {`{d:[]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'd', 0, 0, 0, 0, 0, 0}},
{`{e:[]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'e', 0, 0, 0, 0, 0, 0}}, {`{e:[]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'e', 0, 0, 0, 0, 0, 0}},
{`{f:[], g:[]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'f', 0, 0, 0, 0, 0, 9, 0, 1, 'g', 0, 0, 0, 0, 0, 0}}, {`{f:[], g:[]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'f', 0, 0, 0, 0, 0, 9, 0, 1, 'g', 0, 0, 0, 0, 0, 0}},
{`{a:[{b:3B}]}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'a', 10, 0, 0, 0, 1, 1, 0, 1, 'b', 3, 0, 0}},
// issue#121 // issue#121
{`{a:[b],c:0B}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'a', 8, 0, 0, 0, 1, 0, 1, 'b', 1, 0, 1, 'c', 0, 0}}, {`{a:[b],c:0B}`, TagCompound, []byte{10, 0, 0, 9, 0, 1, 'a', 8, 0, 0, 0, 1, 0, 1, 'b', 1, 0, 1, 'c', 0, 0}},