Naughty: Catch invalid markup in notifications
Previously, an invalid markup caused an empty popup. Since the C core now throws a lua error on invalid markup, we have a way to notice that something is wrong. This patch first tries to set the notification's text the same way we did previously. If that fails, everything is escaped and the result is used as the text for the notification. Thanks to farhaven/Gregor Best for the initial version of this and for the string.gsub() call I stole from him. :) Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
711d78b50c
commit
6fa27c7b48
|
@ -9,6 +9,7 @@ local pairs = pairs
|
||||||
local table = table
|
local table = table
|
||||||
local type = type
|
local type = type
|
||||||
local string = string
|
local string = string
|
||||||
|
local pcall = pcall
|
||||||
local capi = { screen = screen,
|
local capi = { screen = screen,
|
||||||
awesome = awesome,
|
awesome = awesome,
|
||||||
dbus = dbus,
|
dbus = dbus,
|
||||||
|
@ -354,9 +355,19 @@ function notify(args)
|
||||||
local textbox = capi.widget({ type = "textbox", align = "flex" })
|
local textbox = capi.widget({ type = "textbox", align = "flex" })
|
||||||
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
||||||
layout.margins[textbox] = { right = margin, left = margin, bottom = margin, top = margin }
|
layout.margins[textbox] = { right = margin, left = margin, bottom = margin, top = margin }
|
||||||
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text:gsub("<br.->", "\n"))
|
|
||||||
textbox.valign = "middle"
|
textbox.valign = "middle"
|
||||||
|
|
||||||
|
local function setText(pattern, replacements)
|
||||||
|
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text:gsub(pattern, replacements))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- First try to set the text while only interpreting <br>.
|
||||||
|
-- (Setting a textbox' .text to an invalid pattern throws a lua error)
|
||||||
|
if not pcall(setText, "<br.->", "\n") then
|
||||||
|
-- That failed, escape everything which might cause an error from pango
|
||||||
|
setText("[<>&]", { ['<'] = "<", ['>'] = ">", ['&'] = "&" })
|
||||||
|
end
|
||||||
|
|
||||||
-- create iconbox
|
-- create iconbox
|
||||||
local iconbox = nil
|
local iconbox = nil
|
||||||
if icon then
|
if icon then
|
||||||
|
|
Loading…
Reference in New Issue