RESOLVED FIXED157723
RegExp /y flag incorrect handling of mixed-length alternation
https://bugs.webkit.org/show_bug.cgi?id=157723
Summary RegExp /y flag incorrect handling of mixed-length alternation
Steven Levithan
Reported 2016-05-15 02:16:15 PDT
This issue broke the XRegExp library. I've added a workaround in XRegExp 3.1.1 -- see <https://github.com/slevithan/xregexp/issues/135>. Safari Technology Preview v9.1.1 has a bug in its handling of the ES 2015 RegExp /y flag. Here is some test output, with the last example showing the bug: ``` /a|b/y.test('a'); // -> true /a|b/y.test('b'); // -> true /b|a/y.test('a'); // -> true /b|a/y.test('b'); // -> true /aa|bb/y.test('aa'); // -> true /aa|bb/y.test('bb'); // -> true /bb|aa/y.test('aa'); // -> true /bb|aa/y.test('bb'); // -> true /a|bb/y.test('a'); // -> true /a|bb/y.test('bb'); // -> true /bb|a/y.test('bb'); // -> true /bb|a/y.test('a'); // -> false [should be true] ``` It seems that if a regex with flag y evaluates a path within a regex with more than 1 character, it advances its internal lastIndex that the y flag is anchored to, and does not reset this position when the alternative fails and another path in the regex with fewer characters to match is tried. Or something along those lines. Safari 9.1 does not have this issue, since 9.1.1 is the first version to support /y. Also, no other current browser that supports /y (Edge, Firefox, Chrome, Opera) has this bug.
Attachments
Patch (10.79 KB, patch)
2016-05-16 07:44 PDT, Michael Saboff
msaboff: review+
msaboff: commit-queue-
Radar WebKit Bug Importer
Comment 1 2016-05-15 07:01:10 PDT
Michael Saboff
Comment 2 2016-05-15 22:07:46 PDT
The problem is in the YARR JIT, the interpreter works fine. Seems that the existing alternative backtracking code for dissimilar alternative sizes was bailing for sticky mode. There was code we didn't emit for sticky patterns. Have a patch in the works that emits the code to properly back track for dissimilar alternatives, but it still doesn't advance to try the next index.
Michael Saboff
Comment 3 2016-05-16 07:44:54 PDT
Michael Saboff
Comment 4 2016-05-16 10:18:54 PDT
Comment on attachment 279017 [details] Patch r=filip
Michael Saboff
Comment 5 2016-05-16 10:34:39 PDT
Comment on attachment 279017 [details] Patch Going to commit manually.
Michael Saboff
Comment 6 2016-05-16 10:39:20 PDT
Mathias Bynens
Comment 7 2016-05-16 10:40:33 PDT
…That was quick. Thanks, Michael!
Steven Levithan
Comment 8 2016-05-16 22:36:53 PDT
Thanks for the fast fix! Glad this won't make it to a stable browser and make adoption of /y harder.
Note You need to log in before you can comment on or make changes to this bug.