[gnome-calendar/gnome-3-24] event-widget: properly escape event description



commit ace26e90608618ae69af1414b0470fff69587134
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon May 8 21:26:21 2017 -0300

    event-widget: properly escape event description
    
    When we escape first, then truncate, we might end up truncating at
    the middle of a special character sequence, breaking the markup.
    
    Fix that by escaping after truncating.

 src/gcal-event-widget.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index 14add39..25aceda 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -247,9 +247,10 @@ gcal_event_widget_set_event_tooltip (GcalEventWidget *self,
                                      GcalEvent       *event)
 {
   g_autoptr (GDateTime) tooltip_start, tooltip_end;
-  g_autofree gchar *start, *end, *escaped_summary, *escaped_description;
+  g_autofree gchar *start, *end, *escaped_summary;
+  GString *tooltip_mesg;
   gboolean allday, multiday, is_ltr;
-  GString *tooltip_desc, *tooltip_mesg;
+  guint description_len;
 
   tooltip_mesg = g_string_new (NULL);
   escaped_summary = g_markup_escape_text (gcal_event_get_summary (event), -1);
@@ -363,25 +364,32 @@ gcal_event_widget_set_event_tooltip (GcalEventWidget *self,
       g_string_append_printf (tooltip_mesg, "%s", escaped_location);
     }
 
-  escaped_description = g_markup_escape_text (gcal_event_get_description (event), -1);
-  tooltip_desc = g_string_new (escaped_description);
+  description_len = g_utf8_strlen (gcal_event_get_description (event), -1);
 
   /* Truncate long descriptions at a white space and ellipsize */
-  if (tooltip_desc->len > 0)
+  if (description_len > 0)
     {
+      g_autofree gchar *escaped_description;
+      GString *tooltip_desc;
+
+      tooltip_desc = g_string_new (gcal_event_get_description (event));
+
       /* If the description is larger than DESC_MAX_CHAR, ellipsize it */
-      if (g_utf8_strlen (tooltip_desc->str, -1) > DESC_MAX_CHAR)
+      if (description_len > DESC_MAX_CHAR)
         {
           g_string_truncate (tooltip_desc, DESC_MAX_CHAR - 1);
           g_string_append (tooltip_desc, "…");
         }
 
-      g_string_append_printf (tooltip_mesg, "\n\n%s", tooltip_desc->str);
+      escaped_description = g_markup_escape_text (tooltip_desc->str, -1);
+
+      g_string_append_printf (tooltip_mesg, "\n\n%s", escaped_description);
+
+      g_string_free (tooltip_desc, TRUE);
     }
 
   gtk_widget_set_tooltip_markup (GTK_WIDGET (self), tooltip_mesg->str);
 
-  g_string_free (tooltip_desc, TRUE);
   g_string_free (tooltip_mesg, TRUE);
 }
 


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