aboutsummaryrefslogtreecommitdiffstats
path: root/util/format.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-05-30 13:41:05 +0200
committerKim Alvefur <zash@zash.se>2019-05-30 13:41:05 +0200
commit236abc4afed5321e0da406e369a8b23dac6fef83 (patch)
tree081f89c13f1e99ee994923454030effe81b09778 /util/format.lua
parent2a65eae651302a17c925e0340e59e73976aa07fb (diff)
downloadprosody-236abc4afed5321e0da406e369a8b23dac6fef83.tar.gz
prosody-236abc4afed5321e0da406e369a8b23dac6fef83.zip
util.format: Handle formats expecting an integer in Lua 5.3+ (fixes #1371)
Diffstat (limited to 'util/format.lua')
-rw-r--r--util/format.lua6
1 files changed, 6 insertions, 0 deletions
diff --git a/util/format.lua b/util/format.lua
index c31f599f..857bb694 100644
--- a/util/format.lua
+++ b/util/format.lua
@@ -7,6 +7,9 @@ local unpack = table.unpack or unpack; -- luacheck: ignore 113/unpack
local pack = require "util.table".pack; -- TODO table.pack in 5.2+
local type = type;
local dump = require "util.serialization".new("debug");
+local num_type = math.type;
+
+local expects_integer = num_type and { c = true, d = true, i = true, o = true, u = true, X = true, x = true, } or {};
local function format(formatstring, ...)
local args = pack(...);
@@ -43,6 +46,9 @@ local function format(formatstring, ...)
elseif type(arg) ~= "number" then -- arg isn't number as expected?
args[i] = tostring(arg);
spec = "[%s]";
+ elseif expects_integer[option] and num_type(arg) ~= "integer" then
+ args[i] = tostring(arg);
+ spec = "[%s]";
end
end
return spec;