diff --git a/pkg/yqlib/lib.go b/pkg/yqlib/lib.go index 65389263..144fed9f 100644 --- a/pkg/yqlib/lib.go +++ b/pkg/yqlib/lib.go @@ -338,7 +338,7 @@ func deepCloneWithOptions(node *yaml.Node, cloneContent bool) *yaml.Node { Tag: node.Tag, Value: node.Value, Anchor: node.Anchor, - Alias: deepClone(node.Alias), + Alias: node.Alias, HeadComment: node.HeadComment, LineComment: node.LineComment, FootComment: node.FootComment, diff --git a/pkg/yqlib/operator_assign_test.go b/pkg/yqlib/operator_assign_test.go index 4a7cd208..47fcaa4c 100644 --- a/pkg/yqlib/operator_assign_test.go +++ b/pkg/yqlib/operator_assign_test.go @@ -4,6 +4,11 @@ import ( "testing" ) +var mergeAnchorAssign = `a: &a + x: OriginalValue +b: + <<: *a` + var assignOperatorScenarios = []expressionScenario{ { description: "Create yaml file", @@ -20,6 +25,14 @@ var assignOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::a: null\n", }, }, + { + skipDoc: true, + document: mergeAnchorAssign, + expression: `.c = .b | .a.x = "ModifiedValue" | explode(.)`, + expected: []string{ + "D0, P[], (doc)::a:\n x: ModifiedValue\nb:\n x: ModifiedValue\nc:\n x: ModifiedValue\n", + }, + }, { skipDoc: true, document: "{}",