Skip to content

Fix delpaths with negative array indices in non-leaf positions#3543

Open
eyupcanakman wants to merge 1 commit into
jqlang:masterfrom
eyupcanakman:fix/delpaths-negative-nonleaf-indices
Open

Fix delpaths with negative array indices in non-leaf positions#3543
eyupcanakman wants to merge 1 commit into
jqlang:masterfrom
eyupcanakman:fix/delpaths-negative-nonleaf-indices

Conversation

@eyupcanakman
Copy link
Copy Markdown

del and delpaths reconcile a positive and a negative array index that hit the same element when both sit at the leaf of a path. Non-leaf positions are different. delpaths_sorted compares path components directly, so a negative non-leaf index runs as a separate deletion against the array already shortened by the positive one. On [[0,1,2,3,4,5,6,7,8,9]], del(.[0][-6], .[-1][6]) gives [[0,1,2,4,5,7,8,9]] instead of [[0,1,2,3,5,7,8,9]]. Resolve negative indices against the array length at each level before grouping, like the leaf level does.

Fixes #3538

delpaths resolves a positive and a negative array index against the same
element at the leaf level (jv_dels), but the grouping in delpaths_sorted
compared path components directly, so a negative index in a non-leaf
position was applied as a separate deletion against the array already
shortened by the positive one. Resolve negative indices to their positive
equivalents at each array level before grouping.

Fixes jqlang#3538
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent delpaths behavior with negative indices

1 participant