Skip to content

Commit

Permalink
Fixes append map bug when key matches value in existing map #1200
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Apr 28, 2022
1 parent 26529fa commit 67c79b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/yqlib/operator_add.go
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/yqlib/operator_add_test.go
Expand Up @@ -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]]`,
Expand Down

0 comments on commit 67c79b7

Please sign in to comment.