Bug 210576 - Certain regexes with range-quantified groups fail to match
Summary: Certain regexes with range-quantified groups fail to match
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-15 15:58 PDT by Ross Kirsling
Modified: 2020-04-19 16:47 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Kirsling 2020-04-15 15:58:10 PDT
I'm not even sure what to title this, but I extracted it from test262/harness/testIntl.js.

The following is false for JSC but true for all other engines:
```
/(?:\w+-)+((\w){5,8})-\1/.test('de-gregory-gregory')
```

This was as far as I could manage to shrink the regex.
(The backreference can be inlined and the nested group can be made a non-capturing group, but everything else seems needed?)
Comment 1 Devin Rousso 2020-04-15 16:04:01 PDT
This works tho 🤔

```
/(?:\w+-)+(\w{5,8})-\1/.test('de-gregory-gregory')
```
Comment 2 Ross Kirsling 2020-04-15 16:05:14 PDT Comment hidden (obsolete)
Comment 3 Alexey Shvayka 2020-04-15 16:06:36 PDT
(In reply to Ross Kirsling from comment #0)
> The following is false for JSC but true for all other engines:

Same result in Safari 12.1. I wonder if it's the same issue as in https://bugs.webkit.org/show_bug.cgi?id=188407?
Comment 4 Devin Rousso 2020-04-15 16:07:52 PDT Comment hidden (obsolete)
Comment 5 Ross Kirsling 2020-04-19 16:42:16 PDT
Alexey noticed that my shrunken regex in comment 0 succeeds with a `u` flag, but the original regex does not. If we unshrink just a bit, this fails:

  /(?:\w+-)+((\w){5,8})-((\w){5,8}-)*\1/u.test('de-gregory-gregory')

...which may suggest multiple issues at play.


I also kept trying ways to further shrink/restrict the comment 0 regex and noticed that the following fails (with or without `u`):

  /^(?:aa~)+(?:a){2,3}~aa?a?a?$/.test('aa~aa~aaaa')

...so nested groups may not be necessary, but that (?:a){2,3} is really important. It needs to be a quantified group with a lower bound greater than 1 and an upper bound greater than the lower bound. (Presumably the bound restrictions are needed so that it doesn't get automatically simplified?)