naughty: Try ignoring all markup before giving up
naughty now tries to ignore all pango markup by using :set_text() instead of :set_markup(). If this fails, too, we must have been fed invalid utf8 which we cannot do anything about. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
ec72ee1b43
commit
ecb8376c44
|
@ -356,16 +356,22 @@ function notify(args)
|
||||||
marginbox:set_widget(textbox)
|
marginbox:set_widget(textbox)
|
||||||
textbox.valign = "middle"
|
textbox.valign = "middle"
|
||||||
|
|
||||||
local function setText(pattern, replacements)
|
local function setMarkup(pattern, replacements)
|
||||||
textbox:set_markup(string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text:gsub(pattern, replacements)))
|
textbox:set_markup(string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text:gsub(pattern, replacements)))
|
||||||
end
|
end
|
||||||
|
local function setText()
|
||||||
|
textbox:set_text(string.format('%s %s', title, text)
|
||||||
|
end
|
||||||
|
|
||||||
-- First try to set the text while only interpreting <br>.
|
-- First try to set the text while only interpreting <br>.
|
||||||
-- (Setting a textbox' .text to an invalid pattern throws a lua error)
|
-- (Setting a textbox' .text to an invalid pattern throws a lua error)
|
||||||
if not pcall(setText, "<br.->", "\n") then
|
if not pcall(setMarkup, "<br.->", "\n") then
|
||||||
-- That failed, escape everything which might cause an error from pango
|
-- That failed, escape everything which might cause an error from pango
|
||||||
if not pcall(setText, "[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" }) then
|
if not pcall(setMarkup, "[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" }) then
|
||||||
textbox:set_markup("<i><Invalid markup, cannot display message></i>")
|
-- Ok, just ignore all pango markup. If this fails, we got some invalid utf8
|
||||||
|
if not pcall(setText) then
|
||||||
|
textbox:set_markup("<i><Invalid markup or UTF8, cannot display message></i>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue