Skip to content

Commit

Permalink
Fix indices/1 and rindex/1 in case of overlapping matches in strings
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele6 committed Jul 14, 2023
1 parent 24871fb commit a9ba230
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ jv jv_string_indexes(jv j, jv k) {
p = jstr;
while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {
a = jv_array_append(a, jv_number(p - jstr));
p += idxlen;
p++;
}
}
jv_free(j);
Expand Down
4 changes: 4 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,10 @@ split("")
"a,bc,def,ghij,klmno"
[1,13,[1,4,8,13]]

[ index("aba"), rindex("aba"), indices("aba") ]
"xababababax"
[1,7,[1,3,5,7]]

indices(1)
[0,1,1,2,3,4,1,5]
[1,2,6]
Expand Down

0 comments on commit a9ba230

Please sign in to comment.