From 11a2c34a69798f96540b4e9aad16256e4a11978c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0pa=C4=8Dek?= Date: Tue, 27 Oct 2020 11:24:19 +0100 Subject: [PATCH] krprint: escape non-printable strings in error messages All strings should be properly escaped but some non-escaped versions were leaking into error messages. --- daemon/lua/krprint.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/daemon/lua/krprint.lua b/daemon/lua/krprint.lua index 2bd4dd73f..e60880186 100644 --- a/daemon/lua/krprint.lua +++ b/daemon/lua/krprint.lua @@ -46,7 +46,12 @@ function base_class._fallback(self, val) elseif self.on_unrepresentable == 'error' then local key_path_msg if #self.tab_key_path > 0 then - local key_path = '[' .. table.concat(self.tab_key_path, '][') .. ']' + local str_key_path = {} + for _, key in ipairs(self.tab_key_path) do + table.insert(str_key_path, + string.format('%s %s', type(key), self:string(tostring(key)))) + end + local key_path = '[' .. table.concat(str_key_path, '][') .. ']' key_path_msg = string.format(' (found at [%s])', key_path) else key_path_msg = '' @@ -192,8 +197,8 @@ function base_class.table(self, tab) item = item .. string.format('%s%s%s,', indent, note, valexpr) else local errmsg = string.format('cannot print %s = %s (%s)', - tostring(idx), - tostring(val), + self:string(tostring(idx)), + self:string(tostring(val)), table.concat(errors, ', ')) if self.on_unrepresentable == 'error' then error(errmsg, 0) -- 2.47.2