From a9ba23000b6e8333beb678c4c4c8d03fd9bffd8d Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Sat, 15 Jul 2023 00:27:40 +0200 Subject: [PATCH] Fix indices/1 and rindex/1 in case of overlapping matches in strings Fixes #2433 --- src/jv.c | 2 +- tests/jq.test | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jv.c b/src/jv.c index facc59609a..498a14149d 100644 --- a/src/jv.c +++ b/src/jv.c @@ -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); diff --git a/tests/jq.test b/tests/jq.test index 4a8bfeee0c..ebaefdb8cd 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -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]