Skip to content

Commit

Permalink
Don't wrap negative indices twice (fix #2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Aug 6, 2023
1 parent a692060 commit 29e39ae
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,16 +694,16 @@ jv jq_next(jq_state *jq) {
set_error(jq, jv_invalid_with_msg(msg));
goto do_backtrack;
}
// $array | .[-1]
if (jv_get_kind(k) == JV_KIND_NUMBER && jv_get_kind(t) == JV_KIND_ARRAY) {
int idx = jv_number_value(k);
if (idx < 0) {
jv_free(k);
k = jv_number(jv_array_length(jv_copy(t)) + idx);
}
}
jv v = jv_get(t, jv_copy(k));
if (jv_is_valid(v)) {
// $array | .[-1]
if (jv_get_kind(k) == JV_KIND_NUMBER && jv_get_kind(t) == JV_KIND_ARRAY) {
int idx = jv_number_value(k);
if (idx < 0) {
jv_free(k);
k = jv_number(jv_array_length(jv_copy(t)) + idx);
}
}
path_append(jq, k, jv_copy(v));
stack_push(jq, v);
} else {
Expand Down

0 comments on commit 29e39ae

Please sign in to comment.