mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
fix RegExp sticky polyfill with alternation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user