You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(function () {
"use strict";
var regexp = /\S+/g;
var string = "one two three";
regexp.lastIndex = string.indexOf(" ") + 1; // match all after the first space character
var results = Array.from(string.matchAll(regexp));
console.log(results.length); // Expected 2
console.log(results[0]); // Expected ["two", index: 4, ...]
console.log(results[1]); // Expected ["three", index: 8, ...]
}());
does not reliably detect empty-string matches in at least Internet Explorer. The following approach, using match.index, seems to work reliably
var fullUnicode = Boolean(regexCopy.unicode); // 8. Let fullUnicode be O.[[Unicode]].
var matchStr = match[0]; // 11.a.i. Let matchStr be ? ToString(? Get(match, "0")).
if (!matchStr) { // 11.a.ii. If matchStr is the empty String, then
regexCopy.lastIndex = match.index + 1 + ( // 11.a.ii.1. Let thisIndex be ? ToLength(? Get(R, "lastIndex")).
fullUnicode && // 11.a.ii.2. Let nextIndex be ! AdvanceStringIndex(S, thisIndex, fullUnicode).
isSurrogatePair(string, match.index) // 11.a.ii.3. Perform ? Set(R, "lastIndex", nextIndex, true).
);
}
Of course, without any additional polyfill, fullUnicode would be false in Internet Explorer.
The text was updated successfully, but these errors were encountered:
Andrew-Cottrell
changed the title
String#matchAll polyfill does not appear to Let lastIndex be ? ToLength(? Get(R, "lastIndex")).
String#matchAll polyfill does not appear to correctly set or update the lastIndex property
Jun 4, 2020
closure-compiler/src/com/google/javascript/jscomp/js/es6/string/matchall.js
Line 48 in 3ae91f3
The
String#matchAll
polyfill fails this test caseThe polyfill does not appear to implement steps 7-8 of RegExp.prototype [ @@matchAll ].
The polyfill also doesn't appear to fully implement step 11.a.ii.2 of %RegExpStringIteratorPrototype%.next or AdvanceStringIndex, which require incrementing lastIndex by 2 when the Unicode flag is set and the next 2 code units form a surrogate pair.
Note, the comparison at
closure-compiler/src/com/google/javascript/jscomp/js/es6/string/matchall.js
Line 64 in 3ae91f3
match.index
, seems to work reliablyOf course, without any additional polyfill,
fullUnicode
would befalse
in Internet Explorer.The text was updated successfully, but these errors were encountered: