Fixed xml decode bug when there is content after a comment

This commit is contained in:
Mike Farah 2022-11-25 13:21:19 +11:00
parent 51043770bf
commit 43233ce62e
3 changed files with 6 additions and 17 deletions

View File

@ -59,22 +59,6 @@ yq -P sample.json
return err return err
} }
inputFormatType, err := yqlib.InputFormatFromString(inputFormat)
if err != nil {
return err
}
if (inputFormatType == yqlib.XMLInputFormat &&
outputFormatType != yqlib.XMLOutputFormat ||
inputFormatType != yqlib.XMLInputFormat &&
outputFormatType == yqlib.XMLOutputFormat) &&
yqlib.ConfiguredXMLPreferences.AttributePrefix == "+@" {
yqlib.GetLogger().Warning("The default xml-attribute-prefix has changed in the v4.30 to `+@` to avoid " +
"naming conflicts with the default content name, directive name and proc inst prefix. If you need to keep " +
"`+` please set that value explicityly with --xml-attribute-prefix.")
}
if outputFormatType == yqlib.YamlOutputFormat || if outputFormatType == yqlib.YamlOutputFormat ||
outputFormatType == yqlib.PropsOutputFormat { outputFormatType == yqlib.PropsOutputFormat {
unwrapScalar = true unwrapScalar = true

View File

@ -245,7 +245,7 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
} }
case xml.CharData: case xml.CharData:
// Extract XML data (if any) // Extract XML data (if any)
elem.n.Data = trimNonGraphic(string(se)) elem.n.Data = elem.n.Data + trimNonGraphic(string(se))
if elem.n.Data != "" { if elem.n.Data != "" {
elem.state = "chardata" elem.state = "chardata"
log.Debug("chardata [%v] for %v", elem.n.Data, elem.label) log.Debug("chardata [%v] for %v", elem.n.Data, elem.label)

View File

@ -233,6 +233,11 @@ const expectedXmlWithProcInstAndDirectives = `<?xml version="1.0"?>
` `
var xmlScenarios = []formatScenario{ var xmlScenarios = []formatScenario{
{
skipDoc: true,
input: "<root>value<!-- comment--> </root>",
expected: "root: value # comment\n",
},
{ {
description: "Parse xml: simple", description: "Parse xml: simple",
subdescription: "Notice how all the values are strings, see the next example on how you can fix that.", subdescription: "Notice how all the values are strings, see the next example on how you can fix that.",