Skip to content

Commit

Permalink
Fixes issue when update against self #1869
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Nov 18, 2023
1 parent 4b8c850 commit 3d64bda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/yqlib/candidate_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/yqlib/operator_assign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "{}",
Expand Down

0 comments on commit 3d64bda

Please sign in to comment.