mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +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"
|
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
|
source ./scripts/shunit2
|
@ -126,6 +126,9 @@ func (dec *xmlDecoder) convertToYamlNode(n *xmlNode) (*yaml.Node, error) {
|
|||||||
return dec.createMap(n)
|
return dec.createMap(n)
|
||||||
}
|
}
|
||||||
scalar := createScalarNode(n.Data, n.Data)
|
scalar := createScalarNode(n.Data, n.Data)
|
||||||
|
if n.Data == "" {
|
||||||
|
scalar = createScalarNode(nil, "")
|
||||||
|
}
|
||||||
log.Debug("scalar headC: %v, footC: %v", n.HeadComment, n.FootComment)
|
log.Debug("scalar headC: %v, footC: %v", n.HeadComment, n.FootComment)
|
||||||
scalar.HeadComment = dec.processComment(n.HeadComment)
|
scalar.HeadComment = dec.processComment(n.HeadComment)
|
||||||
scalar.LineComment = dec.processComment(n.LineComment)
|
scalar.LineComment = dec.processComment(n.LineComment)
|
||||||
@ -149,6 +152,8 @@ func (dec *xmlDecoder) Decode(rootYamlNode *yaml.Node) error {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if firstNode.Tag == "!!null" {
|
||||||
|
return io.EOF
|
||||||
}
|
}
|
||||||
rootYamlNode.Kind = yaml.DocumentNode
|
rootYamlNode.Kind = yaml.DocumentNode
|
||||||
rootYamlNode.Content = []*yaml.Node{firstNode}
|
rootYamlNode.Content = []*yaml.Node{firstNode}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ func decodeXml(t *testing.T, s formatScenario) *CandidateNode {
|
|||||||
|
|
||||||
node := &yaml.Node{}
|
node := &yaml.Node{}
|
||||||
err := decoder.Decode(node)
|
err := decoder.Decode(node)
|
||||||
if err != nil {
|
if err != nil && err != io.EOF {
|
||||||
t.Error(err, "fail to decode", s.input)
|
t.Error(err, "fail to decode", s.input)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +267,34 @@ var xmlScenarios = []formatScenario{
|
|||||||
expected: expectedDecodeYamlWithComments,
|
expected: expectedDecodeYamlWithComments,
|
||||||
scenarioType: "decode",
|
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",
|
description: "Parse xml: with comments subchild",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user