From f1dd53edd2422c110dd366630d02d7f39f9a09fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sun, 21 Oct 2018 15:22:40 +0700 Subject: [PATCH] Escape XML entities by default Since most Awesome widgets provide set_widget method, texts are likely to be parsed to Pango which consume these entities and may fail on invalid ones. --- init.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 4e32213..206aeb5 100644 --- a/init.lua +++ b/init.lua @@ -52,10 +52,19 @@ local function update(widget, reg, disablecache) local function format_data(data) local ret if type(data) == "table" then + local escaped_data = {} + for k, v in pairs(data) do + if type(v) == "string" then + escaped_data[k] = helpers.escape(v) + else + escaped_data[k] = v + end + end + if type(reg.format) == "string" then - ret = helpers.format(reg.format, data) + ret = helpers.format(reg.format, escaped_data) elseif type(reg.format) == "function" then - ret = reg.format(widget, data) + ret = reg.format(widget, escaped_data) end end return ret or data