Fix string.gsub behaviour with negative n

This commit is contained in:
Enrico Horn
2021-07-09 23:46:34 +02:00
parent 6b9dece367
commit 560a4694e4
5 changed files with 5 additions and 0 deletions

View File

@@ -640,6 +640,8 @@ public class StringLib extends TwoArgFunction {
int lastmatch = -1; /* end of last match */
LuaValue repl = args.arg(3);
int max_s = args.optint(4, srclen+1);
if (max_s < 0)
max_s = srclen+1;
final boolean anchor = p.length() > 0 && p.charAt(0) == '^';
Buffer lbuf = new Buffer(srclen);