Fixed delete bug

This commit is contained in:
Mike Farah 2021-02-04 12:48:07 +11:00
parent 3a464272d4
commit 10600dd29a
2 changed files with 18 additions and 2 deletions

View File

@ -13,8 +13,8 @@ func deleteChildOperator(d *dataTreeNavigator, context Context, expressionNode *
if err != nil { if err != nil {
return Context{}, err return Context{}, err
} }
//need to iterate backwards to ensure correct indices when deleting multiple
for el := nodesToDelete.MatchingNodes.Front(); el != nil; el = el.Next() { for el := nodesToDelete.MatchingNodes.Back(); el != nil; el = el.Prev() {
candidate := el.Value.(*CandidateNode) candidate := el.Value.(*CandidateNode)
deleteImmediateChildOp := &Operation{ deleteImmediateChildOp := &Operation{

View File

@ -37,6 +37,22 @@ var deleteOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::[1, 3]\n", "D0, P[], (doc)::[1, 3]\n",
}, },
}, },
{
skipDoc: true,
document: `a: [1,2,3]`,
expression: `del(.a[])`,
expected: []string{
"D0, P[], (doc)::a: []\n",
},
},
{
skipDoc: true,
document: `a: [10,x,10, 10, x, 10]`,
expression: `del(.a[] | select(. == 10))`,
expected: []string{
"D0, P[], (doc)::a: [x, x]\n",
},
},
{ {
description: "Delete nested entry in array", description: "Delete nested entry in array",
document: `[{a: cat, b: dog}]`, document: `[{a: cat, b: dog}]`,