[Xfce4-commits] <xfce4-notifyd:master> Parse body with g_markup_escape_text (bug #7773, #8187).

Jérôme Guelfucci noreply at xfce.org
Sat Dec 8 18:06:01 CET 2012


Updating branch refs/heads/master
         to a5f0108f7a1dd679338cd5cc185169b86955592d (commit)
       from a27059e3198ab3b4bd92dd60e5ed44779a956e25 (commit)

commit a5f0108f7a1dd679338cd5cc185169b86955592d
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Sat Dec 8 18:01:50 2012 +0100

    Parse body with g_markup_escape_text (bug #7773, #8187).

 NEWS                               |    3 +
 xfce4-notifyd/xfce-notify-window.c |  164 +-----------------------------------
 2 files changed, 4 insertions(+), 163 deletions(-)

diff --git a/NEWS b/NEWS
index 9c0c2e4..743b4b8 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ Version 0.2.3git:
     * Fix notifications not disappearing after clicking an action button.
     * Add a category to the settings dialog for Xfce4 Settings Manager.
     * Handle timeout correctly when smaller than fading time (bug #8580).
+    * Parse body with g_markup_escape_text which allows us to handle
+      span attributes missused by some clients and to parse strings with
+      "unusual" caracters such as & (bug #7773, #8187).
 
 Version 0.2.2 (06 August 2011):
 
diff --git a/xfce4-notifyd/xfce-notify-window.c b/xfce4-notifyd/xfce-notify-window.c
index 6df2512..496c08f 100644
--- a/xfce4-notifyd/xfce-notify-window.c
+++ b/xfce4-notifyd/xfce-notify-window.c
@@ -751,168 +751,6 @@ elem_to_string(gconstpointer elem_p)
     }
 }
 
-static gchar *
-xfce_notify_window_validate_escape_markup(const gchar *str)
-{
-    GString *gstr;
-    const gchar *p;
-    GQueue *open_elems;
-    gconstpointer tmp;
-
-    if(!str)
-        return NULL;
-
-    open_elems = g_queue_new();
-    gstr = g_string_sized_new(strlen(str));
-    p = str;
-
-    while(*p) {
-        if('<' == *p) {
-            if('b' == *(p+1) && '>' == *(p+2)) {
-                g_queue_push_head(open_elems, ELEM_B);
-                g_string_append(gstr, "<b>");
-                p += 3;
-            } else if('i' == *(p+1) && '>' == *(p+2)) {
-                g_queue_push_head(open_elems, ELEM_I);
-                g_string_append(gstr, "<i>");
-                p += 3;
-            } else if('u' == *(p+1) && '>' == *(p+2)) {
-                g_queue_push_head(open_elems, ELEM_U);
-                g_string_append(gstr, "<u>");
-                p += 3;
-            } else if('a' == *(p+1) && ' ' == *(p+2)) {
-                gchar *aend;
-
-                g_queue_push_head(open_elems, ELEM_A);
-
-                aend = strchr(p+3, '>');
-                if(!aend) {
-                    g_warning("Bad markup in <a>: %s", str);
-                    goto out_err;
-                }
-#if GTK_CHECK_VERSION(2,16,0)
-                /* only support links with gtk 2.16 */
-                g_string_append_len(gstr, p, aend - p + 1);
-#endif
-                p = aend + 1;
-            } else if(!strncmp(p+1, "img ", 4)) {
-                /* don't currently support images; extract alt text
-                 * if available */
-                gchar *imgend, *altbegin, *altend = NULL;
-
-                altbegin = strstr(p+5, "alt=\"");
-                if(altbegin) {
-                    altbegin += 5;
-                    altend = strchr(altbegin, '"');
-                    if(!altend) {
-                        g_warning("End of <img> alt text not found");
-                        goto out_err;
-                    }
-                }
-
-                imgend = strstr(altend ? altend+1 : p+4, "/>");
-                if(!imgend) {
-                    g_warning("Unclosed <img> tag");
-                    goto out_err;
-                }
-
-                if(altbegin) {
-                    /* put the alt text in the label */
-                    g_string_append_c(gstr, '[');
-                    g_string_append(gstr, _("image: "));
-                    p = altbegin;
-                    while(p < altend) {
-                        if(*p == '<')
-                            g_string_append(gstr, "<");
-                        else if(*p == '>')
-                            g_string_append(gstr, ">");
-                        else if(*p == '&')
-                            g_string_append(gstr, "&");
-                        else
-                            g_string_append_c(gstr, *p);
-                        p++;
-                    }
-                    g_string_append_c(gstr, ']');
-                }
-
-                p = imgend + 2;
-            } else if('/' == *(p+1)) {
-                if('b' == *(p+2) && '>' == *(p+3)) {
-                    tmp = g_queue_pop_head(open_elems);
-                    if(tmp != ELEM_B) {
-                        g_warning("Bad markup: closing <b> when %s expected",
-                                  elem_to_string(tmp));
-                        goto out_err;
-                    }
-                    g_string_append(gstr, "</b>");
-                    p += 4;
-                } else if('i' == *(p+2) && '>' == *(p+3)) {
-                    tmp = g_queue_pop_head(open_elems);
-                    if(tmp != ELEM_I) {
-                        g_warning("Bad markup: closing <i> when %s expected",
-                                  elem_to_string(tmp));
-                        goto out_err;
-                    }
-                    g_string_append(gstr, "</i>");
-                    p += 4;
-                } else if('u' == *(p+2) && '>' == *(p+3)) {
-                    tmp = g_queue_pop_head(open_elems);
-                    if(tmp != ELEM_U) {
-                        g_warning("Bad markup: closing <u> when %s expected",
-                                  elem_to_string(tmp));
-                        goto out_err;
-                    }
-                    g_string_append(gstr, "</u>");
-                    p += 4;
-                } else if('a' == *(p+2) && '>' == *(p+3)) {
-                    tmp = g_queue_pop_head(open_elems);
-                    if(tmp != ELEM_A) {
-                        g_warning("Bad markup: closing <a> when %s expected",
-                                  elem_to_string(tmp));
-                        goto out_err;
-                    }
-#if GTK_CHECK_VERSION(2,16,0)
-                    g_string_append(gstr, "</a>");
-#endif
-                    p += 4;
-                } else {
-                    g_string_append(gstr, "<");
-                    p++;
-                }
-            } else {
-                g_string_append(gstr, "<");
-                p++;
-            }
-        } else if('>' == *p) {
-            g_string_append(gstr, ">");
-            p++;
-        } else {
-            const gchar *next = g_utf8_next_char(p);
-
-            if(!next) {
-                g_critical("Bad UTF-8 in string");
-                goto out_err;
-            }
-
-            g_string_append_len(gstr, p, next - p);
-            p = next;
-        }
-    }
-
-    p = gstr->str;
-    g_string_free(gstr, FALSE);
-    g_queue_free(open_elems);
-
-    return (gchar *)p;
-
-out_err:
-    g_string_free(gstr, TRUE);
-    g_queue_free(open_elems);
-    return NULL;
-}
-
-
-
 GtkWidget *
 xfce_notify_window_new(void)
 {
@@ -981,7 +819,7 @@ xfce_notify_window_set_body(XfceNotifyWindow *window,
     g_return_if_fail(XFCE_IS_NOTIFY_WINDOW(window));
 
     if(body && *body) {
-        gchar *markup = xfce_notify_window_validate_escape_markup(body);
+        gchar *markup = g_markup_escape_text (body, -1);
         if(!markup)
             return;
 


More information about the Xfce4-commits mailing list