-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Milestone
Description
Description
Some regular expressions behave weirdly when matches are zero length - they miss matches or match too often.
Reproduction
Case 1
Input:
jq --null-input --compact-output '"xx"|match("";"g")'
Output:
{"offset":0,"length":0,"string":"","captures":[]}
{"offset":1,"length":0,"string":"","captures":[]}
Expected:
{"offset":0,"length":0,"string":"","captures":[]}
{"offset":1,"length":0,"string":"","captures":[]}
{"offset":2,"length":0,"string":"","captures":[]}
There should be a match at the end of the string too.
Case 2
Input:
$ jq --null-input --compact-output '"xx"|match("$";"g")'
Output:
{"offset":2,"length":0,"string":"","captures":[]}
{"offset":2,"length":0,"string":"","captures":[]}
Expected:
{"offset":2,"length":0,"string":"","captures":[]}
The same match shouldn't show up twice. (Extra matches seem to be returned in number equal to the length of the string, for some reason. But they're all the same match at the same offset.)
Environment
- OS and Version: Ubuntu
- jq version: master branch, commit cff5336
Additional context
I stumbled on this trying to fix #2148 and found that my attempted solution didn't behave like I expected it to. I tried to isolate the problem and ended up with these.