dualfroz b0f3a8b909 fix(xml): panic when encoding a sequence tagged as a map
The pre-pass that emits processing instructions first walks Content in
key/value pairs, which is only valid for a mapping, but it gated on
node.Tag instead of node.Kind. A sequence tagged !!map can have an odd
Content length, so Content[i+1] ran off the end:

    printf '!!map [cat, dog, fish]\n' | yq -o=xml
    panic: runtime error: index out of range [3] with length 3

That pre-pass runs before the switch on node.Kind, which would otherwise
have returned the usual 'cannot encode ... to XML' error.

The same check also skipped well formed mappings that carry a custom
tag, so their processing instructions were dropped: encodeTopLevelMap
then skipped the key as already processed and it disappeared from the
output altogether.

Gate the pre-pass on Kind, as the rest of the file already does in the
switch in Encode, in doEncode and in encodeMap.
2026-09-03 14:32:13 +02:00
S
Description
My contributions to mikefarah/yq: 3 commits
56 KiB
0 Stars 1 Watchers 0 Forks
Languages
Go 100%