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+

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>