summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lstrlib.js4
-rw-r--r--tests/single.lua1
2 files changed, 3 insertions, 2 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index cd95a60..03c6358 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -204,9 +204,9 @@ const addquoted = function(b, s) {
} else if (iscntrl(s[0])) {
let buff = [];
if (!isdigit(s[1]))
- buff = lua.to_luastring(sprintf("\\%d", s[0]).split('').map(e => e.charCodeAt(0)));
+ buff = lua.to_luastring(sprintf("\\%d", s[0]));
else
- buff = lua.to_luastring(sprintf("\\%03d", s[0]).split('').map(e => e.charCodeAt(0)));
+ buff = lua.to_luastring(sprintf("\\%03d", s[0]));
concat(b, buff);
} else
b.push(s[0]);
diff --git a/tests/single.lua b/tests/single.lua
index e206568..e3ba2f5 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -150,3 +150,4 @@ end
x = '"ílo"\n\\'
assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\')
+assert(string.format('%q', "\0") == [["\0"]])