Parcourir la source

Have RegExp.prototype.test work correctly when lastIndex > MaxCharCount

Gorkem Yakin il y a 10 ans
Parent
commit
9511ebcaf4

+ 1 - 1
lib/Runtime/Library/RegexHelper.cpp

@@ -674,7 +674,7 @@ namespace Js
         const bool isSticky = pattern->IsSticky();
         const bool isSticky = pattern->IsSticky();
         CharCount offset;
         CharCount offset;
         if (!GetInitialOffset(isGlobal, isSticky, regularExpression, inputLength, offset))
         if (!GetInitialOffset(isGlobal, isSticky, regularExpression, inputLength, offset))
-            return false;
+            return scriptContext->GetLibrary()->GetFalse();
 
 
         if (offset <= inputLength)
         if (offset <= inputLength)
         {
         {

+ 5 - 0
test/UnifiedRegex/lastIndex.baseline

@@ -115,6 +115,11 @@ test(/(?:)/g /*lastIndex=0*/ , "axbxcxd", 4);
 true
 true
 r.lastIndex=4
 r.lastIndex=4
 RegExp.${_,1,...,9}=["axbxcxd","","","","","","","","",""]
 RegExp.${_,1,...,9}=["axbxcxd","","","","","","","","",""]
+****** lastIndex above MaxCharCount
+test(/x/g /*lastIndex=0*/ , "axbxcxd", 9007199254740991);
+false
+r.lastIndex=0
+RegExp.${_,1,...,9}=["axbxcxd","","","","","","","","",""]
 *************
 *************
 *** Match ***
 *** Match ***
 *************
 *************

+ 2 - 0
test/UnifiedRegex/lastIndex.js

@@ -275,6 +275,8 @@ test(rel, s1, 4);
 echo("****** Global empty regex");
 echo("****** Global empty regex");
 test(reg, s1, 0);
 test(reg, s1, 0);
 test(reg, s1, 4);
 test(reg, s1, 4);
+echo("****** lastIndex above MaxCharCount");
+test(rg, s1, Number.MAX_SAFE_INTEGER);
 
 
 echo("*************");
 echo("*************");
 echo("*** Match ***");
 echo("*** Match ***");