[balsa] libbalsa/information: Use g_markup_escape_text



commit 1b06e7faab591588a6a9e93e0fdd96aaeec43625
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Sep 14 16:52:55 2018 -0400

    libbalsa/information: Use g_markup_escape_text
    
    * libbalsa/information.c (libbalsa_information_varg): use
      g_markup_escape_text to entity-escape the body of a
      GNotification, instead of our home-brewed non-UTF8-safe version.

 ChangeLog              |  6 ++++++
 libbalsa/information.c | 32 ++++++--------------------------
 2 files changed, 12 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e7f88516a..d0186c50e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-14  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       * libbalsa/information.c (libbalsa_information_varg): use
+         g_markup_escape_text to entity-escape the body of a
+         GNotification, instead of our home-brewed non-UTF8-safe version.
+
 2018-09-05  Albrecht Dreß  <albrecht dress arcor de>
 
        Fix crash listing S/MIME certificates
diff --git a/libbalsa/information.c b/libbalsa/information.c
index 7fdc5e83f..2cb339bf1 100644
--- a/libbalsa/information.c
+++ b/libbalsa/information.c
@@ -41,8 +41,8 @@ void
 libbalsa_information_varg(GtkWindow *parent, LibBalsaInformationType type,
                           const char *fmt, va_list ap)
 {
-    gchar *msg, *p, *q;
-    GString *escaped;
+    gchar *msg;
+    gchar *escaped;
     const gchar *icon_str;
     GIcon *icon;
     gboolean send;
@@ -74,32 +74,12 @@ libbalsa_information_varg(GtkWindow *parent, LibBalsaInformationType type,
     msg = g_strdup_vprintf(fmt, ap);
     /* GNotification uses HTML markup (???), so we must replace '<' and
      * '&' with the corresponding entity in the message string. */
-    escaped = g_string_new(NULL);
-    for (p = msg; (q = strpbrk(p, "<>&\"")) != NULL; p = ++q) {
-        g_string_append_len(escaped, p, q - p);
-        switch (*q) {
-        case '<':
-            g_string_append(escaped, "&lt;");
-            break;
-        case '>':
-            g_string_append(escaped, "&gt;");
-            break;
-        case '&':
-            g_string_append(escaped, "&amp;");
-            break;
-        case '"':
-            g_string_append(escaped, "&quot;");
-            break;
-        default:
-            break;
-        }
-    }
-    g_string_append(escaped, p);
+    escaped = g_markup_escape_text(msg, -1);
     g_free(msg);
 
-    g_notification_set_body(notification, escaped->str);
-    send = *escaped->str != '\0';
-    g_string_free(escaped, TRUE);
+    g_notification_set_body(notification, escaped);
+    send = escaped[0] != '\0';
+    g_free(escaped);
 
     g_object_set_data(G_OBJECT(notification), "send", GINT_TO_POINTER(send));
     g_signal_emit_by_name(notification, "notify", NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]