Skip to content

Commit

Permalink
Fixing sef fault on bad XML #1888
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Dec 5, 2023
1 parent 1c3d551 commit d474bb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/yqlib/decoder_xml.go
Expand Up @@ -299,6 +299,10 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
log.Debug("chardata [%v] for %v", elem.n.Data, elem.label)
}
case xml.EndElement:
if elem == nil {
log.Debug("no element, probably bad xml")
continue
}
log.Debug("end element %v", elem.label)
elem.state = "finished"
// And add it to its parent list
Expand Down
6 changes: 6 additions & 0 deletions pkg/yqlib/xml_test.go
Expand Up @@ -263,6 +263,12 @@ const expectedXmlWithProcInstAndDirectives = `<?xml version="1.0"?>
`

var xmlScenarios = []formatScenario{
{
skipDoc: true,
description: "bad xml",
input: `<?xml version="1.0" encoding="UTF-8"?></Child></Root>`,
expected: "+p_xml: version=\"1.0\" encoding=\"UTF-8\"\n",
},
{
skipDoc: true,
input: " <root>value<!-- comment--> </root>",
Expand Down

0 comments on commit d474bb8

Please sign in to comment.