From 3d64bdadc1277399d4cf5823b7fcf27e852d2f02 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 18 Nov 2023 12:19:27 +1100 Subject: [PATCH] Fixes issue when update against self #1869 --- pkg/yqlib/candidate_node.go | 5 ++++- pkg/yqlib/operator_assign_test.go | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/candidate_node.go b/pkg/yqlib/candidate_node.go index fbee0d10..488eed25 100644 --- a/pkg/yqlib/candidate_node.go +++ b/pkg/yqlib/candidate_node.go @@ -368,7 +368,10 @@ func (n *CandidateNode) doCopy(cloneContent bool) *CandidateNode { // updates this candidate from the given candidate node func (n *CandidateNode) UpdateFrom(other *CandidateNode, prefs assignPreferences) { - + if n == other { + log.Debugf("UpdateFrom, no need to update from myself.") + return + } // if this is an empty map or empty array, use the style of other node. if (n.Kind != ScalarNode && len(n.Content) == 0) || // if the tag has changed (e.g. from str to bool) diff --git a/pkg/yqlib/operator_assign_test.go b/pkg/yqlib/operator_assign_test.go index 601223ae..67e92526 100644 --- a/pkg/yqlib/operator_assign_test.go +++ b/pkg/yqlib/operator_assign_test.go @@ -17,6 +17,15 @@ var assignOperatorScenarios = []expressionScenario{ "D0, P[], ()::a:\n b: cat\nx: frog\n", }, }, + { + description: "Create yaml file", + document: "a: {b: 3}", + expression: `.a |= .`, + skipDoc: true, + expected: []string{ + "D0, P[], (!!map)::a: {b: 3}\n", + }, + }, { skipDoc: true, document: "{}",