Bug 214181 - RegExp sticky not matching alternates correctly, ignoring lastIndex requirement
Summary: RegExp sticky not matching alternates correctly, ignoring lastIndex requirement
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 13
Hardware: Mac macOS 10.15
: P2 Normal
Assignee: Michael Saboff
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-10 04:52 PDT by eoind
Modified: 2020-08-07 08:51 PDT (History)
8 users (show)

See Also:


Attachments
Screenshot of Safari console (27.33 KB, image/png)
2020-07-10 04:52 PDT, eoind
no flags Details
Patch (6.54 KB, patch)
2020-08-06 21:40 PDT, Michael Saboff
ysuzuki: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description eoind 2020-07-10 04:52:42 PDT
Created attachment 403958 [details]
Screenshot of Safari console

Regular expressions sticky flag is not working correctly when used with alternates (|)

Demonstration: (In Safari 13 JS console)

Entering `/a|aa/y.exec("_a")` returns `["a"]` when it should return `null`. This is because matches should be restricted to starting at lastIndex which in this case is index 0.

Chrome, Firefox and Edge all correctly return `null`

Further proof that this is a bug can be seen as follows. Obviously /a|aa/ should be exactly the same as /(a|aa)/ as capturing groups are not relevant. But entering `/(a|aa)/y.exec("_a")` returns `null`.

Similarly wrapping the rhs of the alternate expression shouldn't affect the result but `/a|(aa)/y.exec("_a")` also correctly returns `null`.

This bug seems related to this bug from 2010: https://bugs.webkit.org/show_bug.cgi?id=48102
Comment 1 Radar WebKit Bug Importer 2020-07-10 12:47:51 PDT
<rdar://problem/65357986>
Comment 2 Michael Saboff 2020-08-06 21:39:36 PDT
Thanks for the bug report.
Comment 3 Michael Saboff 2020-08-06 21:40:03 PDT
Created attachment 406153 [details]
Patch
Comment 4 Yusuke Suzuki 2020-08-06 21:51:37 PDT
Comment on attachment 406153 [details]
Patch

r=me
Comment 5 Michael Saboff 2020-08-07 08:51:35 PDT
Committed r265373: <https://trac.webkit.org/changeset/265373>