Fix a frontier pattern match
We're not in C anymore. LuaString are not null terminated. Also need quotes in error messages.
This commit is contained in:
@@ -972,19 +972,19 @@ public class StringLib extends TwoArgFunction {
|
|||||||
switch ( p.luaByte( poffset++ ) ) {
|
switch ( p.luaByte( poffset++ ) ) {
|
||||||
case L_ESC:
|
case L_ESC:
|
||||||
if ( poffset == p.length() ) {
|
if ( poffset == p.length() ) {
|
||||||
error( "malformed pattern (ends with %)" );
|
error( "malformed pattern (ends with '%')" );
|
||||||
}
|
}
|
||||||
return poffset + 1;
|
return poffset + 1;
|
||||||
|
|
||||||
case '[':
|
case '[':
|
||||||
if ( p.luaByte( poffset ) == '^' ) poffset++;
|
if ( poffset != p.length() && p.luaByte( poffset ) == '^' ) poffset++;
|
||||||
do {
|
do {
|
||||||
if ( poffset == p.length() ) {
|
if ( poffset == p.length() ) {
|
||||||
error( "malformed pattern (missing ])" );
|
error( "malformed pattern (missing ']')" );
|
||||||
}
|
}
|
||||||
if ( p.luaByte( poffset++ ) == L_ESC && poffset != p.length() )
|
if ( p.luaByte( poffset++ ) == L_ESC && poffset < p.length() )
|
||||||
poffset++;
|
poffset++; /* skip escapes (e.g. '%]') */
|
||||||
} while ( p.luaByte( poffset ) != ']' );
|
} while ( poffset == p.length() || p.luaByte( poffset ) != ']' );
|
||||||
return poffset + 1;
|
return poffset + 1;
|
||||||
default:
|
default:
|
||||||
return poffset;
|
return poffset;
|
||||||
@@ -1073,8 +1073,8 @@ public class StringLib extends TwoArgFunction {
|
|||||||
continue;
|
continue;
|
||||||
case 'f': {
|
case 'f': {
|
||||||
poffset += 2;
|
poffset += 2;
|
||||||
if ( p.luaByte( poffset ) != '[' ) {
|
if ( poffset == p.length() || p.luaByte( poffset ) != '[' ) {
|
||||||
error("Missing [ after %f in pattern");
|
error("Missing '[' after '%f' in pattern");
|
||||||
}
|
}
|
||||||
int ep = classend( poffset );
|
int ep = classend( poffset );
|
||||||
int previous = ( soffset == 0 ) ? '\0' : s.luaByte( soffset - 1 );
|
int previous = ( soffset == 0 ) ? '\0' : s.luaByte( soffset - 1 );
|
||||||
|
|||||||
Reference in New Issue
Block a user