Fixing readonly ops not to modify context when paths dont exist

This commit is contained in:
Mike Farah
2021-05-16 14:00:30 +10:00
parent afebf0e621
commit 3f51a44596
12 changed files with 95 additions and 18 deletions
+10 -3
View File
@@ -12,14 +12,21 @@ func hasOperator(d *dataTreeNavigator, context Context, expressionNode *Expressi
log.Debugf("-- hasOperation")
var results = list.New()
rhs, err := d.GetMatchingNodes(context, expressionNode.Rhs)
wanted := rhs.MatchingNodes.Front().Value.(*CandidateNode).Node
wantedKey := wanted.Value
readonlyContext := context.Clone()
readonlyContext.DontAutoCreate = true
rhs, err := d.GetMatchingNodes(readonlyContext, expressionNode.Rhs)
if err != nil {
return Context{}, err
}
wantedKey := "null"
wanted := &yaml.Node{Tag: "!!null"}
if rhs.MatchingNodes.Len() != 0 {
wanted = rhs.MatchingNodes.Front().Value.(*CandidateNode).Node
wantedKey = wanted.Value
}
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)