Skip to content

Commit 43233ce

Browse files
committed
Fixed xml decode bug when there is content after a comment
1 parent 5104377 commit 43233ce

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

cmd/root.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ yq -P sample.json
5959
return err
6060
}
6161

62-
inputFormatType, err := yqlib.InputFormatFromString(inputFormat)
63-
64-
if err != nil {
65-
return err
66-
}
67-
68-
if (inputFormatType == yqlib.XMLInputFormat &&
69-
outputFormatType != yqlib.XMLOutputFormat ||
70-
inputFormatType != yqlib.XMLInputFormat &&
71-
outputFormatType == yqlib.XMLOutputFormat) &&
72-
yqlib.ConfiguredXMLPreferences.AttributePrefix == "+@" {
73-
yqlib.GetLogger().Warning("The default xml-attribute-prefix has changed in the v4.30 to `+@` to avoid " +
74-
"naming conflicts with the default content name, directive name and proc inst prefix. If you need to keep " +
75-
"`+` please set that value explicityly with --xml-attribute-prefix.")
76-
}
77-
7862
if outputFormatType == yqlib.YamlOutputFormat ||
7963
outputFormatType == yqlib.PropsOutputFormat {
8064
unwrapScalar = true

pkg/yqlib/decoder_xml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
245245
}
246246
case xml.CharData:
247247
// Extract XML data (if any)
248-
elem.n.Data = trimNonGraphic(string(se))
248+
elem.n.Data = elem.n.Data + trimNonGraphic(string(se))
249249
if elem.n.Data != "" {
250250
elem.state = "chardata"
251251
log.Debug("chardata [%v] for %v", elem.n.Data, elem.label)

pkg/yqlib/xml_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ const expectedXmlWithProcInstAndDirectives = `<?xml version="1.0"?>
233233
`
234234

235235
var xmlScenarios = []formatScenario{
236+
{
237+
skipDoc: true,
238+
input: "<root>value<!-- comment--> </root>",
239+
expected: "root: value # comment\n",
240+
},
236241
{
237242
description: "Parse xml: simple",
238243
subdescription: "Notice how all the values are strings, see the next example on how you can fix that.",

0 commit comments

Comments
 (0)