diff --git a/pkg/yqlib/operator_delete.go b/pkg/yqlib/operator_delete.go index 63f05f81d8..653a40cd8c 100644 --- a/pkg/yqlib/operator_delete.go +++ b/pkg/yqlib/operator_delete.go @@ -81,6 +81,7 @@ func deleteFromArray(node *CandidateNode, childPath interface{}) { shouldDelete := fmt.Sprintf("%v", index) == fmt.Sprintf("%v", childPath) if !shouldDelete { + value.Key.Value = fmt.Sprintf("%v", len(newContents)) newContents = append(newContents, value) } } diff --git a/pkg/yqlib/operator_delete_test.go b/pkg/yqlib/operator_delete_test.go index 473b329a39..cae7bc83d2 100644 --- a/pkg/yqlib/operator_delete_test.go +++ b/pkg/yqlib/operator_delete_test.go @@ -179,6 +179,15 @@ var deleteOperatorScenarios = []expressionScenario{ "D0, P[], (!!map)::{a: {b: {age: 12}}}\n", }, }, + { + skipDoc: true, + description: "Repeatedly delete the first element of a list", + document: `a: [0, 1, 2, 3]`, + expression: `del(.a[0]) | del(.a[0])`, + expected: []string{ + "D0, P[], (!!map)::a: [2, 3]\n", + }, + }, } func TestDeleteOperatorScenarios(t *testing.T) {