Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when converting array to XML #1408

Closed
opax opened this issue Nov 2, 2022 · 2 comments
Closed

Panic when converting array to XML #1408

opax opened this issue Nov 2, 2022 · 2 comments
Labels

Comments

@opax
Copy link

opax commented Nov 2, 2022

Describe the bug

When converting an array to XML, yq exits with a panic.

Version of yq: 4.29.2
Operating system: mac
Installed via: homebrew

Command

yq -o x . <<<'[5]'

Actual behavior

panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/mikefarah/yq/v4/pkg/yqlib.(*xmlEncoder).encodeTopLevelMap(0x14000396d00, 0x0?, 0x140003acb40)
	github.com/mikefarah/yq/v4/pkg/yqlib/encoder_xml.go:95 +0x7ec
github.com/mikefarah/yq/v4/pkg/yqlib.(*xmlEncoder).Encode(0x14000396d00, {0x1033ff888?, 0x140000136c0?}, 0x140003aca00)
	github.com/mikefarah/yq/v4/pkg/yqlib/encoder_xml.go:68 +0x324
github.com/mikefarah/yq/v4/pkg/yqlib.(*resultsPrinter).printNode(0x14000396d00?, 0x0?, {0x1033ff888?, 0x140000136c0?})
	github.com/mikefarah/yq/v4/pkg/yqlib/printer.go:82 +0x100
github.com/mikefarah/yq/v4/pkg/yqlib.(*resultsPrinter).PrintResults(0x14000072540, 0x140003aa540)
	github.com/mikefarah/yq/v4/pkg/yqlib/printer.go:133 +0x568
...

Expected behavior

Either

  • a proper error message ("Arrays cannot be converted to XML")
  • or nothing (which is the current behavior for other not-representable data formats, e.g. yq -o x . <<< 5 does not output anything and signals no error)
@mikefarah
Copy link
Owner

Thanks - will fix in the next release. I think a proper error message is the right approach 👍🏼

mikefarah added a commit that referenced this issue Nov 2, 2022
@mikefarah
Copy link
Owner

Fixed in 4.30.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants