Fixed issue on creating objects using []

This commit is contained in:
Mike Farah 2021-06-11 14:27:44 +10:00
parent 01267d062b
commit 88bee2809f
3 changed files with 17 additions and 3 deletions

View File

@ -127,9 +127,16 @@ func traverseArrayIndices(context Context, matchingNode *CandidateNode, indicesT
node := matchingNode.Node node := matchingNode.Node
if node.Tag == "!!null" { if node.Tag == "!!null" {
log.Debugf("OperatorArrayTraverse got a null - turning it into an empty array") log.Debugf("OperatorArrayTraverse got a null - turning it into an empty array")
// auto vivification, make it into an empty array // auto vivification
node.Tag = "" node.Tag = ""
node.Kind = yaml.SequenceNode node.Kind = yaml.SequenceNode
//check that the indices are numeric, if not, then we should create an object
if len(indicesToTraverse) != 0 {
_, err := strconv.ParseInt(indicesToTraverse[0].Value, 10, 64)
if err != nil {
node.Kind = yaml.MappingNode
}
}
} }
if node.Kind == yaml.AliasNode { if node.Kind == yaml.AliasNode {

View File

@ -43,6 +43,13 @@ var traversePathOperatorScenarios = []expressionScenario{
"D0, P[0 0 0], (!!int)::1\n", "D0, P[0 0 0], (!!int)::1\n",
}, },
}, },
{
skipDoc: true,
expression: `.["cat"] = "thing"`,
expected: []string{
"D0, P[], ()::cat: thing\n",
},
},
{ {
description: "Simple map navigation", description: "Simple map navigation",
document: `{a: {b: apple}}`, document: `{a: {b: apple}}`,