mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed issue on creating objects using []
This commit is contained in:
parent
01267d062b
commit
88bee2809f
@ -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 {
|
||||||
|
@ -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}}`,
|
||||||
|
Loading…
Reference in New Issue
Block a user