diff --git a/pkg/yqlib/candidate_node.go b/pkg/yqlib/candidate_node.go index 89c40645..0fd2fe59 100644 --- a/pkg/yqlib/candidate_node.go +++ b/pkg/yqlib/candidate_node.go @@ -61,6 +61,7 @@ func (n *CandidateNode) UpdateFrom(other *CandidateNode) { n.Node.Content = other.Node.Content n.Node.Value = other.Node.Value n.Node.Alias = other.Node.Alias + n.Node.Anchor = other.Node.Anchor } func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode) { diff --git a/pkg/yqlib/doc/Multiply.md b/pkg/yqlib/doc/Multiply.md index 3fc98d53..87ea2d89 100644 --- a/pkg/yqlib/doc/Multiply.md +++ b/pkg/yqlib/doc/Multiply.md @@ -180,7 +180,7 @@ g: thongs f: *cat ``` -## Merge does not copy anchor names +## Merge copies anchor names Given a sample.yml file of: ```yaml a: @@ -197,7 +197,7 @@ yq eval '.c * .a' sample.yml will output ```yaml g: thongs -c: frog +c: &cat frog ``` ## Merge with merge anchors diff --git a/pkg/yqlib/operator_multiply_test.go b/pkg/yqlib/operator_multiply_test.go index d900c000..40819c3a 100644 --- a/pkg/yqlib/operator_multiply_test.go +++ b/pkg/yqlib/operator_multiply_test.go @@ -132,11 +132,11 @@ b: }, }, { - description: "Merge does not copy anchor names", + description: "Merge copies anchor names", document: `{a: {c: &cat frog}, b: {f: *cat}, c: {g: thongs}}`, expression: `.c * .a`, expected: []string{ - "D0, P[c], (!!map)::{g: thongs, c: frog}\n", + "D0, P[c], (!!map)::{g: thongs, c: &cat frog}\n", }, }, {