summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-24 22:05:29 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-03-24 22:05:29 +0100
commit245e582eaad5293fc5b8d4620d140a527c3b42c4 (patch)
tree1e1286e9843195033cba322377626be50f6ee1c1
parent6f42ac9cce2ded1f62cf967f42c85b1171678fa1 (diff)
downloadfengari-245e582eaad5293fc5b8d4620d140a527c3b42c4.tar.gz
fengari-245e582eaad5293fc5b8d4620d140a527c3b42c4.tar.bz2
fengari-245e582eaad5293fc5b8d4620d140a527c3b42c4.zip
Fixed string.format pattern with '.'
-rw-r--r--src/lstrlib.js2
-rw-r--r--tests/single.lua5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 2e623b6..13e325e 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -361,7 +361,7 @@ const str_format = function(L) {
} else {
let zero = s.indexOf(0);
lauxlib.luaL_argcheck(L, zero < 0 || zero === s.length - 1, arg, "string contains zeros");
- if (form.indexOf('.') < 0 && s.length >= 100) {
+ if (form.indexOf('.'.charCodeAt(0)) < 0 && s.length >= 100) {
/* no precision and string is too long to be formatted */
concat(b, s); /* keep entire string */
lapi.lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
diff --git a/tests/single.lua b/tests/single.lua
index c87ac7e..8ca9fbb 100644
--- a/tests/single.lua
+++ b/tests/single.lua
@@ -165,3 +165,8 @@ assert(tonumber(string.format("%f", 10.3)) == 10.3)
x = string.format('"%-50s"', 'a')
assert(#x == 52)
assert(string.sub(x, 1, 4) == '"a ')
+
+assert(string.format("-%.20s.20s", string.rep("%", 2000)) ==
+ "-"..string.rep("%", 20)..".20s")
+assert(string.format('"-%20s.20s"', string.rep("%", 2000)) ==
+ string.format("%q", "-"..string.rep("%", 2000)..".20s"))