diff --git a/pkg/yqlib/context.go b/pkg/yqlib/context.go index e5d9fb83..817527ab 100644 --- a/pkg/yqlib/context.go +++ b/pkg/yqlib/context.go @@ -66,3 +66,9 @@ func (n *Context) ReadOnlyClone() Context { clone.DontAutoCreate = true return clone } + +func (n *Context) WritableClone() Context { + clone := n.Clone() + clone.DontAutoCreate = false + return clone +} diff --git a/pkg/yqlib/operator_multiply.go b/pkg/yqlib/operator_multiply.go index 2cd94f5f..832b5c3c 100644 --- a/pkg/yqlib/operator_multiply.go +++ b/pkg/yqlib/operator_multiply.go @@ -32,11 +32,11 @@ func multiply(preferences multiplyPreferences) func(d *dataTreeNavigator, contex var newBlank = lhs.CreateChild(nil, &yaml.Node{}) - var newThing, err = mergeObjects(d, context, newBlank, lhs, multiplyPreferences{}) + var newThing, err = mergeObjects(d, context.WritableClone(), newBlank, lhs, multiplyPreferences{}) if err != nil { return nil, err } - return mergeObjects(d, context, newThing, rhs, preferences) + return mergeObjects(d, context.WritableClone(), newThing, rhs, preferences) } else if lhs.Node.Tag == "!!int" && rhs.Node.Tag == "!!int" { return multiplyIntegers(lhs, rhs) } else if (lhs.Node.Tag == "!!int" || lhs.Node.Tag == "!!float") && (rhs.Node.Tag == "!!int" || rhs.Node.Tag == "!!float") { diff --git a/pkg/yqlib/operator_multiply_test.go b/pkg/yqlib/operator_multiply_test.go index 1393801f..4de3f90a 100644 --- a/pkg/yqlib/operator_multiply_test.go +++ b/pkg/yqlib/operator_multiply_test.go @@ -47,6 +47,20 @@ var multiplyOperatorScenarios = []expressionScenario{ docExpected, }, }, + { + skipDoc: true, + expression: `.x = {"things": "whatever"} * {}`, + expected: []string{ + "D0, P[], ()::x:\n things: whatever\n", + }, + }, + { + skipDoc: true, + expression: `.x = {} * {"things": "whatever"}`, + expected: []string{ + "D0, P[], ()::x:\n things: whatever\n", + }, + }, { skipDoc: true, expression: `3 * 4.5`,