Fixed merged anchor reference problem #1482

This commit is contained in:
Mike Farah 2023-03-01 13:45:35 +11:00
parent cf8cfbd865
commit 3f1f66a8ee
2 changed files with 14 additions and 1 deletions

View File

@ -338,7 +338,7 @@ func deepCloneWithOptions(node *yaml.Node, cloneContent bool) *yaml.Node {
Tag: node.Tag, Tag: node.Tag,
Value: node.Value, Value: node.Value,
Anchor: node.Anchor, Anchor: node.Anchor,
Alias: deepClone(node.Alias), Alias: node.Alias,
HeadComment: node.HeadComment, HeadComment: node.HeadComment,
LineComment: node.LineComment, LineComment: node.LineComment,
FootComment: node.FootComment, FootComment: node.FootComment,

View File

@ -4,6 +4,11 @@ import (
"testing" "testing"
) )
var mergeAnchorAssign = `a: &a
x: OriginalValue
b:
<<: *a`
var assignOperatorScenarios = []expressionScenario{ var assignOperatorScenarios = []expressionScenario{
{ {
description: "Create yaml file", description: "Create yaml file",
@ -20,6 +25,14 @@ var assignOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::a: null\n", "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, skipDoc: true,
document: "{}", document: "{}",