fix RegExp sticky polyfill with alternation

This commit is contained in:
Denis Pushkarev
2026-02-26 17:13:27 +02:00
parent 14bdcbd551
commit 10f12d3a70
3 changed files with 10 additions and 1 deletions
+1
View File
@@ -31,6 +31,7 @@
- Fixed named backreferences in `RegExp` NCG polyfill
- Fixed some cases of `RegExp` NCG polyfill in combination with other types of groups
- Fixed some cases of `RegExp` NCG polyfill in combination with `dotAll`
- Fixed `RegExp` `sticky` polyfill with alternation
- Fixed handling of some line terminators in case of `multiline` + `sticky` mode in `RegExp` polyfill
- Fixed `.input` slicing on result object with `RegExp` `sticky` mode polyfill
- Fixed handling of empty groups with `global` and `unicode` modes in polyfills
+1 -1
View File
@@ -79,7 +79,7 @@ if (PATCH) {
var prevChar = re.lastIndex > 0 && charAt(str, re.lastIndex - 1);
if (re.lastIndex > 0 &&
(!re.multiline || re.multiline && prevChar !== '\n' && prevChar !== '\r' && prevChar !== '\u2028' && prevChar !== '\u2029')) {
source = '(?: ' + source + ')';
source = '(?: (?:' + source + '))';
strCopy = ' ' + strCopy;
charsAdded++;
}
+8
View File
@@ -94,4 +94,12 @@ if (DESCRIPTORS) {
regex5.lastIndex = 2;
assert.deepEqual(regex5.exec('.\u2029bar'), ['bar'], 'multiline sticky after \\u2029');
});
QUnit.test('RegExp#exec sticky with alternation', assert => {
const re = new RegExp('a|b', 'y');
re.lastIndex = 1;
const result = re.exec('cb');
assert.deepEqual(result, ['b'], 'alternation matches non-first alternative at lastIndex');
assert.same(re.lastIndex, 2, 'lastIndex updated correctly');
});
}