Skip to content

Commit 3d64bda

Browse files
committed
Fixes issue when update against self #1869
1 parent 4b8c850 commit 3d64bda

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/yqlib/candidate_node.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ func (n *CandidateNode) doCopy(cloneContent bool) *CandidateNode {
368368

369369
// updates this candidate from the given candidate node
370370
func (n *CandidateNode) UpdateFrom(other *CandidateNode, prefs assignPreferences) {
371-
371+
if n == other {
372+
log.Debugf("UpdateFrom, no need to update from myself.")
373+
return
374+
}
372375
// if this is an empty map or empty array, use the style of other node.
373376
if (n.Kind != ScalarNode && len(n.Content) == 0) ||
374377
// if the tag has changed (e.g. from str to bool)

pkg/yqlib/operator_assign_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ var assignOperatorScenarios = []expressionScenario{
1717
"D0, P[], ()::a:\n b: cat\nx: frog\n",
1818
},
1919
},
20+
{
21+
description: "Create yaml file",
22+
document: "a: {b: 3}",
23+
expression: `.a |= .`,
24+
skipDoc: true,
25+
expected: []string{
26+
"D0, P[], (!!map)::a: {b: 3}\n",
27+
},
28+
},
2029
{
2130
skipDoc: true,
2231
document: "{}",

0 commit comments

Comments
 (0)