Fix string.gsub for invalid use '%' in replacement string

Check code:
```
print(pcall(load('string.gsub("test", "%S", "A%")')))
print(pcall(load('string.gsub("test", "%S", "%A")')))
```
This commit is contained in:
Enyby
2019-01-03 18:09:00 +02:00
committed by GitHub
parent 870aee2cae
commit 6f5af581e8

View File

@@ -877,8 +877,14 @@ public class StringLib extends TwoArgFunction {
lbuf.append( (byte) b ); lbuf.append( (byte) b );
} else { } else {
++i; // skip ESC ++i; // skip ESC
b = (byte) news.luaByte( i ); b = (byte)(i < l ? news.luaByte( i ) : 0);
if ( !Character.isDigit( (char) b ) ) { if ( !Character.isDigit( (char) b ) ) {
if (b != L_ESC) error( "invalid use of '" + (char)L_ESC +
"' in replacement string: after '" + (char)L_ESC +
"' must be '0'-'9' or '" + (char)L_ESC +
"', but found " + (i < l ? "symbol '" + (char)b + "' with code " + b +
" at pos " + (i + 1) :
"end of string"));
lbuf.append( b ); lbuf.append( b );
} else if ( b == '0' ) { } else if ( b == '0' ) {
lbuf.append( s.substring( soff, e ) ); lbuf.append( s.substring( soff, e ) );