mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
Fixed xml decode bug when there is content after a comment
This commit is contained in:
parent
51043770bf
commit
43233ce62e
16
cmd/root.go
16
cmd/root.go
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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.",
|
||||||
|
Loading…
Reference in New Issue
Block a user