summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lstrlib.js2
-rw-r--r--tests/single.lua6
2 files changed, 7 insertions, 1 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 4bd8664..3a2ea39 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -668,7 +668,7 @@ const str_rep = function(L) {
let n = lauxlib.luaL_checkinteger(L, 2);
let sep = lauxlib.luaL_optstring(L, 3, "");
- lapi.lua_pushstring(L, (s + sep).repeat(n - 1) + s);
+ lapi.lua_pushstring(L, n > 0 ? (s + sep).repeat(n - 1) + s : "");
return 1;
};
diff --git a/tests/single.lua b/tests/single.lua
index c52a6fb..4bd159c 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -93,3 +93,9 @@ assert(string.char(0, string.byte("\xe4"), 0) == "\0\xe4\0")
assert(string.char(string.byte("\xe4l\0óu", 1, -1)) == "\xe4l\0óu")
assert(string.char(string.byte("\xe4l\0óu", 1, 0)) == "")
assert(string.char(string.byte("\xe4l\0óu", -10, 100)) == "\xe4l\0óu")
+
+assert(string.upper("ab\0c") == "AB\0C")
+assert(string.lower("\0ABCc%$") == "\0abcc%$")
+assert(string.rep('teste', 0) == '')
+assert(string.rep('tés\00tê', 2) == 'tés\0têtés\000tê')
+assert(string.rep('', 10) == '')