%% was not handled properly

This commit is contained in:
斟酌 鵬兄 2016-07-03 20:47:20 +08:00
parent 7826ab0b84
commit e4efdf79e5

View File

@ -85,12 +85,24 @@ String.prototype.L = function( ...args )
var a = 0;
while( ~( j = this.indexOf( "%s", i ) ) )
{
i = j + 2;
// handle %% => % literal
if( this[ j - 1 ] == "%" )
{
// How many % in a row?
var nump = -1;
while( this[ j + ( -- nump ) ] == "%" );
// %% => % literal
if( this[ j - 1 ] == "%" ) continue;
// If number of percent is even, this %s is escaped
if( nump % 2 == 0 )
{
i ++;
continue;
}
}
str += this.substring( i, j ) + args[ a ++ ];
i = j + 2;
}
if( str == "" ) return this.replace( "%%", "%" );