diff --git a/daemon/lua/sandbox.lua b/daemon/lua/sandbox.lua index b25a9deb44ddc65cf97e3e9faf01b6a09f38ca84..fe9cba5d9aa857d0febaf9a100e7e972c014a99b 100644 --- a/daemon/lua/sandbox.lua +++ b/daemon/lua/sandbox.lua @@ -151,18 +151,31 @@ function table_print (tt, indent, done) done = done or {} indent = indent or 0 result = "" + -- Convert to printable string (escape unprintable) + local function printable(value) + value = tostring(value) + local bytes = {} + for i = 1, #value do + local c = string.byte(value, i) + if c >= 0x20 and c < 0x7f then table.insert(bytes, string.char(c)) + else table.insert(bytes, '\\'..tostring(c)) + end + if i > 50 then table.insert(bytes, '...') break end + end + return table.concat(bytes) + end if type(tt) == "table" then for key, value in pairs (tt) do result = result .. string.rep (" ", indent) if type (value) == "table" and not done [value] then done [value] = true - result = result .. string.format("[%s] => {\n", tostring (key)) + result = result .. string.format("[%s] => {\n", printable (key)) result = result .. table_print (value, indent + 4, done) result = result .. string.rep (" ", indent) result = result .. "}\n" else result = result .. string.format("[%s] => %s\n", - tostring (key), tostring(value)) + tostring (key), printable(value)) end end else