Skip to content

Commit c16b180

Browse files
janduboismikefarah
authored andcommitted
Make sure to update the key when deleting array elements
1 parent 3bca3a2 commit c16b180

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/yqlib/operator_delete.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func deleteFromArray(node *CandidateNode, childPath interface{}) {
8181
shouldDelete := fmt.Sprintf("%v", index) == fmt.Sprintf("%v", childPath)
8282

8383
if !shouldDelete {
84+
value.Key.Value = fmt.Sprintf("%v", len(newContents))
8485
newContents = append(newContents, value)
8586
}
8687
}

pkg/yqlib/operator_delete_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ var deleteOperatorScenarios = []expressionScenario{
179179
"D0, P[], (!!map)::{a: {b: {age: 12}}}\n",
180180
},
181181
},
182+
{
183+
skipDoc: true,
184+
description: "Repeatedly delete the first element of a list",
185+
document: `a: [0, 1, 2, 3]`,
186+
expression: `del(.a[0]) | del(.a[0])`,
187+
expected: []string{
188+
"D0, P[], (!!map)::a: [2, 3]\n",
189+
},
190+
},
182191
}
183192

184193
func TestDeleteOperatorScenarios(t *testing.T) {

0 commit comments

Comments
 (0)