Skip to content

Commit

Permalink
Fixed merged anchor reference problem #1482
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Mar 1, 2023
1 parent cf8cfbd commit 3f1f66a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/yqlib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions pkg/yqlib/operator_assign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"testing"
)

var mergeAnchorAssign = `a: &a
x: OriginalValue
b:
<<: *a`

var assignOperatorScenarios = []expressionScenario{
{
description: "Create yaml file",
Expand All @@ -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: "{}",
Expand Down

0 comments on commit 3f1f66a

Please sign in to comment.