diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in index cf015c24f..228ff1752 100644 --- a/lib/naughty.lua.in +++ b/lib/naughty.lua.in @@ -303,6 +303,8 @@ function naughty.notify(args) local margin = args.margin or preset.margin local border_width = args.border_width or preset.border_width local position = args.position or preset.position + local escape_pattern = "[<>&]" + local escape_subs = { ['<'] = "<", ['>'] = ">", ['&'] = "&" } -- beautiful local beautiful = bt.get() @@ -376,17 +378,20 @@ function naughty.notify(args) textbox:set_font(font) local function setMarkup(pattern, replacements) - textbox:set_markup(string.format('%s%s', title:gsub(pattern, replacements), text:gsub(pattern, replacements))) + textbox:set_markup(string.format('%s%s', 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
. + -- Since the title cannot contain markup, it must be escaped first so that + -- it is not interpreted by Pango later. + title = title:gsub(escape_pattern, escape_subs) + -- Try to set the text while only interpreting
. -- (Setting a textbox' .text to an invalid pattern throws a lua error) if not pcall(setMarkup, "", "\n") then -- That failed, escape everything which might cause an error from pango - if not pcall(setMarkup, "[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" }) then + if not pcall(setMarkup, escape_pattern, escape_subs) 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>")