From 67c79b7cb1502530f34757ec50b7ff9c24f54c1e Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Thu, 28 Apr 2022 14:45:45 +1000 Subject: [PATCH] Fixes append map bug when key matches value in existing map #1200 --- pkg/yqlib/operator_add.go | 2 +- pkg/yqlib/operator_add_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/operator_add.go b/pkg/yqlib/operator_add.go index 4b10585e..90ccb9b5 100644 --- a/pkg/yqlib/operator_add.go +++ b/pkg/yqlib/operator_add.go @@ -183,7 +183,7 @@ func addMaps(target *CandidateNode, lhsC *CandidateNode, rhsC *CandidateNode) { key := rhs.Content[index] value := rhs.Content[index+1] log.Debug("finding %v", key.Value) - indexInLHS := findInArray(target.Node, key) + indexInLHS := findKeyInMap(target.Node, key) log.Debug("indexInLhs %v", indexInLHS) if indexInLHS < 0 { // not in there, append it diff --git a/pkg/yqlib/operator_add_test.go b/pkg/yqlib/operator_add_test.go index 17d7969e..a98e3faf 100644 --- a/pkg/yqlib/operator_add_test.go +++ b/pkg/yqlib/operator_add_test.go @@ -14,6 +14,14 @@ var addOperatorScenarios = []expressionScenario{ "D0, P[1 a], (!!int)::3\n", }, }, + { + skipDoc: true, + document: `a: key`, + expression: `. += {"key": "b"}`, + expected: []string{ + "D0, P[], (!!map)::a: key\nkey: b\n", + }, + }, { skipDoc: true, document: `[[c], [b]]`,