Fixed create map issue

This commit is contained in:
Mike Farah 2023-05-30 11:34:31 +10:00
parent 82f717226c
commit d033ad570e
8 changed files with 28 additions and 9 deletions

View File

@ -56,7 +56,7 @@ yq '.a + null' sample.yml
```
will output
```yaml
[1, 2, null]
[1, 2]
```
## Append to existing array

View File

@ -31,8 +31,7 @@ In the yaml 1.2 standard, support for yes/no as booleans was dropped - they are
Given a sample.yml file of:
```yaml
- yes
- no
[yes, no]
```
then
```bash

View File

@ -56,6 +56,7 @@ will output
```yaml
Mike: cat
Mike: dog
---
Rosey: monkey
Rosey: sheep
```

View File

@ -85,6 +85,7 @@ will output
```yaml
match: cat
doc: 0
---
match: frog
doc: 1
```

View File

@ -158,7 +158,9 @@ yq '. *= load_props("../../examples/small.properties")' sample.yml
```
will output
```yaml
is
this:
is: a properties file
cool: ay
```
## Load from base64 encoded file

View File

@ -18,6 +18,10 @@ func addAssignOperator(d *dataTreeNavigator, context Context, expressionNode *Ex
}
func toNodes(candidate *CandidateNode, lhs *CandidateNode) []*CandidateNode {
if candidate.Tag == "!!null" {
return []*CandidateNode{}
}
clone := candidate.Copy()
switch candidate.Kind {

View File

@ -49,7 +49,19 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, expres
if err != nil {
return Context{}, err
}
newObject.PushBackList(additions.MatchingNodes)
// we should reset the parents and keys of these top level nodes,
// as they are new
for el := additions.MatchingNodes.Front(); el != nil; el = el.Next() {
addition := el.Value.(*CandidateNode)
additionCopy := addition.Copy()
additionCopy.SetParent(nil)
additionCopy.Key = nil
log.Debugf("-- collectObjectOperation, adding result %v", NodeToString(additionCopy))
newObject.PushBack(additionCopy)
}
}
return context.ChildContext(newObject), nil

View File

@ -17,7 +17,7 @@ var createMapOperatorScenarios = []expressionScenario{
description: "sets key properly",
expression: `("frog": "jumps") | .[0][0] | .frog`,
expected: []string{
"D0, P[frog], (!!str)::jumps\n",
"D0, P[0 0 frog], (!!str)::jumps\n",
},
},
{
@ -32,8 +32,8 @@ var createMapOperatorScenarios = []expressionScenario{
document: `{name: Mike, pets: [cat, dog]}`,
expression: `(.name: .pets.[]) | .[0][0] | ..`,
expected: []string{
"D0, P[], (!!map)::Mike: cat\n",
"D0, P[Mike], (!!str)::cat\n",
"D0, P[0 0], (!!map)::Mike: cat\n",
"D0, P[0 0 Mike], (!!str)::cat\n",
},
},
{
@ -41,7 +41,7 @@ var createMapOperatorScenarios = []expressionScenario{
document: "pets:\n cows: value",
expression: `("b":.pets) | .[0][0] | .b.cows`,
expected: []string{
"D0, P[b cows], (!!str)::value\n",
"D0, P[0 0 b cows], (!!str)::value\n",
},
},
{