mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed xml comment in array of scalars #1465
This commit is contained in:
parent
481ea64ccc
commit
48d00f807e
@ -58,7 +58,7 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*yaml.Node, error) {
|
|||||||
yamlNode := &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"}
|
yamlNode := &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"}
|
||||||
|
|
||||||
if len(n.Data) > 0 {
|
if len(n.Data) > 0 {
|
||||||
log.Debug("creating content node for map")
|
log.Debugf("creating content node for map: %v", dec.prefs.ContentName)
|
||||||
label := dec.prefs.ContentName
|
label := dec.prefs.ContentName
|
||||||
labelNode := createScalarNode(label, label)
|
labelNode := createScalarNode(label, label)
|
||||||
labelNode.HeadComment = dec.processComment(n.HeadComment)
|
labelNode.HeadComment = dec.processComment(n.HeadComment)
|
||||||
@ -78,7 +78,7 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*yaml.Node, error) {
|
|||||||
labelNode.HeadComment = dec.processComment(n.HeadComment)
|
labelNode.HeadComment = dec.processComment(n.HeadComment)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
log.Debugf("label=%v, i=%v, keyValuePair.FootComment: %v", label, i, keyValuePair.FootComment)
|
||||||
labelNode.FootComment = dec.processComment(keyValuePair.FootComment)
|
labelNode.FootComment = dec.processComment(keyValuePair.FootComment)
|
||||||
|
|
||||||
log.Debug("len of children in %v is %v", label, len(children))
|
log.Debug("len of children in %v is %v", label, len(children))
|
||||||
@ -337,8 +337,14 @@ func applyFootComment(elem *element, commentStr string) {
|
|||||||
if len(elem.n.Children) > 0 {
|
if len(elem.n.Children) > 0 {
|
||||||
lastChildIndex := len(elem.n.Children) - 1
|
lastChildIndex := len(elem.n.Children) - 1
|
||||||
childKv := elem.n.Children[lastChildIndex]
|
childKv := elem.n.Children[lastChildIndex]
|
||||||
log.Debug("got a foot comment for %v: [%v]", childKv.K, commentStr)
|
log.Debug("got a foot comment, putting on last child for %v: [%v]", childKv.K, commentStr)
|
||||||
childKv.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ")
|
// if it's an array of scalars, put the foot comment on the scalar itself
|
||||||
|
if len(childKv.V) > 0 && len(childKv.V[0].Children) == 0 {
|
||||||
|
nodeToUpdate := childKv.V[len(childKv.V)-1]
|
||||||
|
nodeToUpdate.FootComment = joinComments([]string{nodeToUpdate.FootComment, commentStr}, " ")
|
||||||
|
} else {
|
||||||
|
childKv.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Debug("got a foot comment for %v: [%v]", elem.label, commentStr)
|
log.Debug("got a foot comment for %v: [%v]", elem.label, commentStr)
|
||||||
elem.n.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ")
|
elem.n.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ")
|
||||||
|
@ -259,6 +259,11 @@ var xmlScenarios = []formatScenario{
|
|||||||
input: "<root>value<!-- comment-->anotherValue </root>",
|
input: "<root>value<!-- comment-->anotherValue </root>",
|
||||||
expected: "root:\n # comment\n - value\n - anotherValue\n",
|
expected: "root:\n # comment\n - value\n - anotherValue\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
input: "<root><cats><cat>quick</cat><cat>soft</cat><!-- kitty_comment--><cat>squishy</cat></cats></root>",
|
||||||
|
expected: "root:\n cats:\n cat:\n - quick\n - soft\n # kitty_comment\n\n - squishy\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