From ecb8376c441526538979cd36334bdc8b601ba7b7 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 14 Jan 2011 16:16:04 +0100 Subject: [PATCH] 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 --- lib/naughty.lua.in | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in index 722b838a6..e00c047b1 100644 --- a/lib/naughty.lua.in +++ b/lib/naughty.lua.in @@ -356,16 +356,22 @@ function notify(args) marginbox:set_widget(textbox) textbox.valign = "middle" - local function setText(pattern, replacements) + local function setMarkup(pattern, replacements) textbox:set_markup(string.format('%s%s', font, title, text:gsub(pattern, replacements))) end + local function setText() + textbox:set_text(string.format('%s %s', title, text) + end -- First try to set the text while only interpreting
. -- (Setting a textbox' .text to an invalid pattern throws a lua error) - if not pcall(setText, "", "\n") then + if not pcall(setMarkup, "", "\n") then -- That failed, escape everything which might cause an error from pango - if not pcall(setText, "[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" }) then - textbox:set_markup("<Invalid markup, cannot display message>") + if not pcall(setMarkup, "[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" }) then + -- Ok, just ignore all pango markup. If this fails, we got some invalid utf8 + if not pcall(setText) then + textbox:set_markup("<Invalid markup or UTF8, cannot display message>") + end end end