Bug 214181

Summary: RegExp sticky not matching alternates correctly, ignoring lastIndex requirement
Product: WebKit Reporter: eoind
Component: JavaScriptCoreAssignee: Michael Saboff <msaboff>
Status: RESOLVED FIXED    
Severity: Normal CC: ews-watchlist, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari 13   
Hardware: Mac   
OS: macOS 10.15   
Attachments:
Description Flags
Screenshot of Safari console
none
Patch ysuzuki: review+

eoind
Reported 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
Attachments
Screenshot of Safari console (27.33 KB, image/png)
2020-07-10 04:52 PDT, eoind
no flags
Patch (6.54 KB, patch)
2020-08-06 21:40 PDT, Michael Saboff
ysuzuki: review+
Radar WebKit Bug Importer
Comment 1 2020-07-10 12:47:51 PDT
Michael Saboff
Comment 2 2020-08-06 21:39:36 PDT
Thanks for the bug report.
Michael Saboff
Comment 3 2020-08-06 21:40:03 PDT
Yusuke Suzuki
Comment 4 2020-08-06 21:51:37 PDT
Comment on attachment 406153 [details] Patch r=me
Michael Saboff
Comment 5 2020-08-07 08:51:35 PDT
Note You need to log in before you can comment on or make changes to this bug.