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.
This commit is contained in:
Nguyễn Gia Phong 2018-10-21 15:22:40 +07:00
parent 873662209c
commit f1dd53edd2
1 changed files with 11 additions and 2 deletions

View File

@ -52,10 +52,19 @@ local function update(widget, reg, disablecache)
local function format_data(data) local function format_data(data)
local ret local ret
if type(data) == "table" then 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 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 elseif type(reg.format) == "function" then
ret = reg.format(widget, data) ret = reg.format(widget, escaped_data)
end end
end end
return ret or data return ret or data