Guarding for infinite loop

This commit is contained in:
斟酌 鵬兄 2016-04-03 23:35:26 +08:00
parent fbb4bae316
commit a72dcd8ca9
2 changed files with 15 additions and 2 deletions

View File

@ -39,7 +39,7 @@
} }
// The root bracket as back ref 0 // The root bracket as back ref 0
var RegEx = new RegExp( "(" + parsed + ")", "g" ); var RegEx = new RegExp( "(" + parsed + ")", "gm" );
return RegEx; return RegEx;
}; };
@ -104,9 +104,20 @@
var FirstHit; var FirstHit;
var PrevStack = []; var PrevStack = [];
var LoopGuard;
while( ( r = search.exec( content ) ) !== null ) while( ( r = search.exec( content ) ) !== null )
{ {
if( !FirstHit ) FirstHit = r.index; if( FirstHit == undefined )
{
FirstHit = r.index;
}
if( LoopGuard == r.index )
{
this.__msg = VimError( "EX2", PATTERN.slice( 1 ).join( "" ) );
return true;
}
if( p < r.index ) if( p < r.index )
{ {
Hit = r.index; Hit = r.index;
@ -114,6 +125,7 @@
} }
PrevStack.push( r.index ); PrevStack.push( r.index );
LoopGuard = r.index;
} }
if( e.kMap( "N" ) ) if( e.kMap( "N" ) )

View File

@ -38,6 +38,7 @@ VIMRE_VERSION = "1.0.0b";
// EXtended Errors // EXtended Errors
, "EX1": "Pattern Error( %1 )" , "EX1": "Pattern Error( %1 )"
, "EX2": "This pattern is causing infinite loop: %1"
, "TODO": "%1 is not implemented yet" , "TODO": "%1 is not implemented yet"
, "MISSING_FEATURE": "Sorry, I thought this command wasn't useful enough to implement. Please file a feature request titled \"Implement %1\" in github if you think this is important." , "MISSING_FEATURE": "Sorry, I thought this command wasn't useful enough to implement. Please file a feature request titled \"Implement %1\" in github if you think this is important."