Fixing sef fault on bad XML #1888

This commit is contained in:
Mike Farah 2023-12-05 13:21:12 +11:00
parent 1c3d551060
commit d474bb8ba4
2 changed files with 10 additions and 0 deletions

View File

@ -299,6 +299,10 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
log.Debug("chardata [%v] for %v", elem.n.Data, elem.label) log.Debug("chardata [%v] for %v", elem.n.Data, elem.label)
} }
case xml.EndElement: case xml.EndElement:
if elem == nil {
log.Debug("no element, probably bad xml")
continue
}
log.Debug("end element %v", elem.label) log.Debug("end element %v", elem.label)
elem.state = "finished" elem.state = "finished"
// And add it to its parent list // And add it to its parent list

View File

@ -263,6 +263,12 @@ const expectedXmlWithProcInstAndDirectives = `<?xml version="1.0"?>
` `
var xmlScenarios = []formatScenario{ 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, skipDoc: true,
input: " <root>value<!-- comment--> </root>", input: " <root>value<!-- comment--> </root>",