summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lstrlib.js2
-rw-r--r--tests/single.lua9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 1294baa..2e623b6 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -366,7 +366,7 @@ const str_format = function(L) {
concat(b, s); /* keep entire string */
lapi.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
} else { /* format the string into 'buff' */
- concat(b, s);
+ concat(b, lua.to_luastring(sprintf(String.fromCharCode(...form), str.jsstring())));
lapi.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
}
}
diff --git a/tests/single.lua b/tests/single.lua
index e8d7210..c87ac7e 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -156,3 +156,12 @@ x = "\0\1\0023\5\0009"
assert(load(string.format('return %q', x))() == x)
assert(string.format("\0%c\0%c%x\0", string.byte("\xe4"), string.byte("b"), 140) ==
"\0\xe4\0b8c\0")
+assert(string.format('') == "")
+assert(string.format("%c",34)..string.format("%c",48)..string.format("%c",90)..string.format("%c",100) ==
+ string.format("%c%c%c%c", 34, 48, 90, 100))
+assert(string.format("%s\0 is not \0%s", 'not be', 'be') == 'not be\0 is not \0be')
+assert(string.format("%%%d %010d", 10, 23) == "%10 0000000023")
+assert(tonumber(string.format("%f", 10.3)) == 10.3)
+x = string.format('"%-50s"', 'a')
+assert(#x == 52)
+assert(string.sub(x, 1, 4) == '"a ')