mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Added github action fix for parsing xml
This commit is contained in:
parent
2891c6948d
commit
06e944dcb6
@ -22,4 +22,22 @@ EOM
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
testInputXmlGithubAction() {
|
||||
cat >test.yml <<EOL
|
||||
<cat legs="4">BiBi</cat>
|
||||
EOL
|
||||
|
||||
read -r -d '' expected << EOM
|
||||
cat:
|
||||
+content: BiBi
|
||||
+legs: "4"
|
||||
EOM
|
||||
|
||||
X=$(cat /dev/null | ./yq e -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
|
||||
X=$(cat /dev/null | ./yq ea -p=xml test.yml)
|
||||
assertEquals "$expected" "$X"
|
||||
}
|
||||
|
||||
source ./scripts/shunit2
|
@ -126,6 +126,9 @@ func (dec *xmlDecoder) convertToYamlNode(n *xmlNode) (*yaml.Node, error) {
|
||||
return dec.createMap(n)
|
||||
}
|
||||
scalar := createScalarNode(n.Data, n.Data)
|
||||
if n.Data == "" {
|
||||
scalar = createScalarNode(nil, "")
|
||||
}
|
||||
log.Debug("scalar headC: %v, footC: %v", n.HeadComment, n.FootComment)
|
||||
scalar.HeadComment = dec.processComment(n.HeadComment)
|
||||
scalar.LineComment = dec.processComment(n.LineComment)
|
||||
@ -149,6 +152,8 @@ func (dec *xmlDecoder) Decode(rootYamlNode *yaml.Node) error {
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if firstNode.Tag == "!!null" {
|
||||
return io.EOF
|
||||
}
|
||||
rootYamlNode.Kind = yaml.DocumentNode
|
||||
rootYamlNode.Content = []*yaml.Node{firstNode}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -18,7 +19,7 @@ func decodeXml(t *testing.T, s formatScenario) *CandidateNode {
|
||||
|
||||
node := &yaml.Node{}
|
||||
err := decoder.Decode(node)
|
||||
if err != nil {
|
||||
if err != nil && err != io.EOF {
|
||||
t.Error(err, "fail to decode", s.input)
|
||||
}
|
||||
|
||||
@ -266,6 +267,34 @@ var xmlScenarios = []formatScenario{
|
||||
expected: expectedDecodeYamlWithComments,
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "Empty doc",
|
||||
skipDoc: true,
|
||||
input: "",
|
||||
expected: "D0, P[], ()::null\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "Empty single node",
|
||||
skipDoc: true,
|
||||
input: "<a/>",
|
||||
expected: "D0, P[], (doc)::a:\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "Empty close node",
|
||||
skipDoc: true,
|
||||
input: "<a></a>",
|
||||
expected: "D0, P[], (doc)::a:\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "Nested empty",
|
||||
skipDoc: true,
|
||||
input: "<a><b/></a>",
|
||||
expected: "D0, P[], (doc)::a:\n b:\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "Parse xml: with comments subchild",
|
||||
skipDoc: true,
|
||||
|
Loading…
Reference in New Issue
Block a user