We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Describe the bug s | rindex(t) yields wrong results when t appears in s with overlapped occurrence.
s | rindex(t)
t
s
To Reproduce
% jq -n '"ababa" | rindex("aba")' 0
Expected behavior Considering rindex should yield the last occurrence index, the result should be 2 since "ababa"[2:] is "aba".
rindex
2
"ababa"[2:]
"aba"
Environment (please complete the following information):
Additional context The filter works well with overlapped occurrence in arrays.
% jq -n '["a","b","a","b","a"] | rindex(["a","b","a"])' 2
This issue is an instance of the inconsistent behavior of indices.
indices
% jq -n '"abababa" | indices("aba")' [ 0, 4 ] % jq -n '["a","b","a","b","a","b","a"] | indices(["a","b","a"])' [ 0, 2, 4 ]
The text was updated successfully, but these errors were encountered:
Fix indices/1 and rindex/1 in case of overlapping matches in strings
a9ba230
Fixes jqlang#2433
@emanuele6 - Any chance of fixing the def ofindex/1 while you're at it?
index/1
The line in builtin.jq says it all: def index($i): indices($i) | .[0]; # TODO: optimize
def index($i): indices($i) | .[0]; # TODO: optimize
Sorry, something went wrong.
1915b68
Fixes #2433
Successfully merging a pull request may close this issue.
Describe the bug
s | rindex(t)
yields wrong results whent
appears ins
with overlapped occurrence.To Reproduce
% jq -n '"ababa" | rindex("aba")' 0
Expected behavior
Considering
rindex
should yield the last occurrence index, the result should be2
since"ababa"[2:]
is"aba"
.Environment (please complete the following information):
Additional context
The filter works well with overlapped occurrence in arrays.
% jq -n '["a","b","a","b","a"] | rindex(["a","b","a"])' 2
This issue is an instance of the inconsistent behavior of
indices
.The text was updated successfully, but these errors were encountered: