diff --git a/pkg/yqlib/operator_assign.go b/pkg/yqlib/operator_assign.go index ff13547..e9695b4 100644 --- a/pkg/yqlib/operator_assign.go +++ b/pkg/yqlib/operator_assign.go @@ -7,7 +7,7 @@ func assignUpdateOperator(d *dataTreeNavigator, context Context, expressionNode } var rhs Context if !expressionNode.Operation.UpdateAssign { - rhs, err = d.GetMatchingNodes(context, expressionNode.Rhs) + rhs, err = d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.Rhs) } for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() { @@ -44,7 +44,7 @@ func assignAttributesOperator(d *dataTreeNavigator, context Context, expressionN for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() { candidate := el.Value.(*CandidateNode) - rhs, err := d.GetMatchingNodes(context.SingleChildContext(candidate), expressionNode.Rhs) + rhs, err := d.GetMatchingNodes(context.SingleReadonlyChildContext(candidate), expressionNode.Rhs) if err != nil { return Context{}, err diff --git a/pkg/yqlib/operator_assign_test.go b/pkg/yqlib/operator_assign_test.go index 54901f7..e9dd748 100644 --- a/pkg/yqlib/operator_assign_test.go +++ b/pkg/yqlib/operator_assign_test.go @@ -12,6 +12,22 @@ var assignOperatorScenarios = []expressionScenario{ "D0, P[], ()::a:\n b: cat\nx: frog\n", }, }, + { + skipDoc: true, + document: "{}", + expression: `.a |= .b`, + expected: []string{ + "D0, P[], (doc)::{a: null}\n", + }, + }, + { + skipDoc: true, + document: "{}", + expression: `.a = .b`, + expected: []string{ + "D0, P[], (doc)::{a: null}\n", + }, + }, { description: "Update node to be the child value", document: `{a: {b: {g: foof}}}`, diff --git a/pkg/yqlib/operator_style.go b/pkg/yqlib/operator_style.go index 693f344..2dfd4a5 100644 --- a/pkg/yqlib/operator_style.go +++ b/pkg/yqlib/operator_style.go @@ -31,7 +31,7 @@ func assignStyleOperator(d *dataTreeNavigator, context Context, expressionNode * log.Debugf("AssignStyleOperator: %v") var style yaml.Style if !expressionNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(context, expressionNode.Rhs) + rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.Rhs) if err != nil { return Context{}, err } @@ -54,7 +54,7 @@ func assignStyleOperator(d *dataTreeNavigator, context Context, expressionNode * candidate := el.Value.(*CandidateNode) log.Debugf("Setting style of : %v", candidate.GetKey()) if expressionNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(context.SingleChildContext(candidate), expressionNode.Rhs) + rhs, err := d.GetMatchingNodes(context.SingleReadonlyChildContext(candidate), expressionNode.Rhs) if err != nil { return Context{}, err } diff --git a/pkg/yqlib/operator_tag.go b/pkg/yqlib/operator_tag.go index 6065350..e447a2f 100644 --- a/pkg/yqlib/operator_tag.go +++ b/pkg/yqlib/operator_tag.go @@ -12,7 +12,7 @@ func assignTagOperator(d *dataTreeNavigator, context Context, expressionNode *Ex tag := "" if !expressionNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(context, expressionNode.Rhs) + rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.Rhs) if err != nil { return Context{}, err } @@ -32,7 +32,7 @@ func assignTagOperator(d *dataTreeNavigator, context Context, expressionNode *Ex candidate := el.Value.(*CandidateNode) log.Debugf("Setting tag of : %v", candidate.GetKey()) if expressionNode.Operation.UpdateAssign { - rhs, err := d.GetMatchingNodes(context.SingleChildContext(candidate), expressionNode.Rhs) + rhs, err := d.GetMatchingNodes(context.SingleReadonlyChildContext(candidate), expressionNode.Rhs) if err != nil { return Context{}, err } diff --git a/pkg/yqlib/operator_union_test.go b/pkg/yqlib/operator_union_test.go index 4171929..417e86b 100644 --- a/pkg/yqlib/operator_union_test.go +++ b/pkg/yqlib/operator_union_test.go @@ -5,6 +5,20 @@ import ( ) var unionOperatorScenarios = []expressionScenario{ + // { + // skipDoc: true, + // document: "{}", + // expression: `(.a, .b.c) as $x`, + // expected: []string{ + // "D0, P[], (doc)::{}\n", + // }, + // }, + // { + // skipDoc: true, + // document: "{}", + // expression: `(.a, .b.c)`, + // expected: []string{}, + // }, { description: "Combine scalars", expression: `1, true, "cat"`, diff --git a/pkg/yqlib/operator_variables.go b/pkg/yqlib/operator_variables.go index 9c498cb..5208132 100644 --- a/pkg/yqlib/operator_variables.go +++ b/pkg/yqlib/operator_variables.go @@ -16,7 +16,7 @@ func getVariableOperator(d *dataTreeNavigator, context Context, expressionNode * } func assignVariableOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { - lhs, err := d.GetMatchingNodes(context, expressionNode.Lhs) + lhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.Lhs) if err != nil { return Context{}, nil } diff --git a/pkg/yqlib/operator_variables_test.go b/pkg/yqlib/operator_variables_test.go index b0fe20a..68ccac1 100644 --- a/pkg/yqlib/operator_variables_test.go +++ b/pkg/yqlib/operator_variables_test.go @@ -5,6 +5,14 @@ import ( ) var variableOperatorScenarios = []expressionScenario{ + { + skipDoc: true, + document: `{}`, + expression: `.a.b as $foo`, + expected: []string{ + "D0, P[], (doc)::{}\n", + }, + }, { description: "Single value variable", document: `a: cat`,