Hi people,

the attached two patches fix a little issue some people had with
naughty. When a notification with broken markup was received, naughty
only displayed a little empty box and issued a warning about broken
pango markup on stderr.

The first patch adds a new read-only textbox property called
well_formed_markup which is true if the markup is okay and false
otherwise.

The second patch uses the new property to escape all HTML entities in a
message if the markup is not valid pango markup.

-- 

    Gregor Best
From 3dcbc73873e4381657b4e17ab4d67c2c78c98d10 Mon Sep 17 00:00:00 2001
From: Gregor Best <g...@ring0.de>
Date: Fri, 16 Jul 2010 12:28:54 +0200
Subject: [PATCH 1/2] textbox: add well_formed_markup property

This read-only property indicates correct pango markup for the text of a
textbox widget.

Signed-off-by: Gregor Best <g...@ring0.de>
---
 common/tokenize.gperf     |    1 +
 objects/widgets/textbox.c |   12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/common/tokenize.gperf b/common/tokenize.gperf
index 40e9154..7d0c0d3 100644
--- a/common/tokenize.gperf
+++ b/common/tokenize.gperf
@@ -96,6 +96,7 @@ urgent
 valign
 version
 visible
+well_formed_markup
 widgets
 width
 window
diff --git a/objects/widgets/textbox.c b/objects/widgets/textbox.c
index 6f4f6c4..f002be0 100644
--- a/objects/widgets/textbox.c
+++ b/objects/widgets/textbox.c
@@ -64,6 +64,8 @@ typedef struct
     bool bg_resize;
     /** Background alignment */
     alignment_t bg_align;
+    /** Is the content well formed markup? */
+    bool well_formed_markup;
 } textbox_data_t;
 
 /** Get an optional padding table from a Lua table.
@@ -251,6 +253,9 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
 
     switch(token)
     {
+      case A_TK_WELL_FORMED_MARKUP:
+        lua_pushboolean(L, d->well_formed_markup);
+        return 1;
       case A_TK_BG_RESIZE:
         lua_pushboolean(L, d->bg_resize);
         return 1;
@@ -382,16 +387,18 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
             {
                 char *text;
                 ssize_t tlen;
+                bool okay;
                 /* if text has been converted to UTF-8 */
                 if(draw_iso2utf8(buf, len, &text, &tlen))
                 {
-                    draw_text_context_init(&d->data, text, tlen);
+                    okay = draw_text_context_init(&d->data, text, tlen);
                     p_delete(&text);
                 }
                 else
-                    draw_text_context_init(&d->data, buf, len);
+                    okay = draw_text_context_init(&d->data, buf, len);
 
                 d->extents = draw_text_extents(&d->data);
+                d->well_formed_markup = okay;
             }
             else
                 p_clear(&d->extents, 1);
@@ -462,6 +469,7 @@ widget_textbox(widget_t *w)
     textbox_data_t *d = w->data = p_new(textbox_data_t, 1);
     d->ellip = PANGO_ELLIPSIZE_END;
     d->valign = AlignCenter;
+    d->well_formed_markup = true;
 
     return w;
 }
-- 
1.7.1.1

From fe11f42d898dcc54c3cf59d26e0faf09b2f172bd Mon Sep 17 00:00:00 2001
From: Gregor Best <g...@ring0.de>
Date: Fri, 16 Jul 2010 12:30:48 +0200
Subject: [PATCH 2/2] naughty: use well_formed_markup textbox property to fix 
broken markup if neccessary

Signed-off-by: Gregor Best <g...@ring0.de>
---
 lib/naughty.lua.in |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in
index 834ffec..1945e5f 100644
--- a/lib/naughty.lua.in
+++ b/lib/naughty.lua.in
@@ -355,6 +355,9 @@ function notify(args)
     textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
     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"))
+    if not textbox.well_formed_markup then
+        textbox.text = string.format('<span 
font_desc="%s"><b>%s</b>%s</span>', font, title, text:gsub("[<>&]", { ['<'] = 
"&lt;", ['>'] = "&gt;", ['&'] = "&amp;" }))
+    end
     textbox.valign = "middle"
 
     -- create iconbox
-- 
1.7.1.1

Attachment: pgpyq6oJZv2LI.pgp
Description: PGP signature

Reply via email to