[evolution/gnome-3-32] I#395 - Escape values in the task/memo preview



commit 22236bf339b35aa7a7ca0266ca2c52097fdbad36
Author: Milan Crha <mcrha redhat com>
Date:   Mon Apr 8 12:16:27 2019 +0200

    I#395 - Escape values in the task/memo preview
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/395

 src/calendar/gui/e-cal-component-preview.c | 115 ++++++++++++++++++-----------
 1 file changed, 70 insertions(+), 45 deletions(-)
---
diff --git a/src/calendar/gui/e-cal-component-preview.c b/src/calendar/gui/e-cal-component-preview.c
index c751817b87..e559f1e996 100644
--- a/src/calendar/gui/e-cal-component-preview.c
+++ b/src/calendar/gui/e-cal-component-preview.c
@@ -182,6 +182,30 @@ timet_to_str_with_zone (ECalComponentDateTime *dt,
        return e_datetime_format_format_tm ("calendar", "table", itt.is_date ? DTFormatKindDate : 
DTFormatKindDateTime, &tm);
 }
 
+static void
+cal_component_preview_add_table_line (GString *buffer,
+                                     const gchar *header,
+                                     const gchar *value)
+{
+       gchar *markup_header, *markup_value;
+
+       g_return_if_fail (buffer != NULL);
+
+       if (!value || !*value)
+               return;
+
+       markup_header = header ? g_markup_escape_text (header, -1) : NULL;
+       markup_value = g_markup_escape_text (value, -1);
+
+       g_string_append_printf (buffer,
+               "<tr><th>%s</th><td>%s</td></tr>",
+               markup_header ? markup_header : "",
+               markup_value);
+
+       g_free (markup_header);
+       g_free (markup_value);
+}
+
 static void
 cal_component_preview_write_html (ECalComponentPreview *preview,
                                   GString *buffer)
@@ -197,8 +221,9 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        icalcomponent *icalcomp;
        icalproperty *icalprop;
        icalproperty_status status;
-       const gchar *location, *url;
+       const gchar *location, *url, *tmp;
        gint *priority_value;
+       gchar *markup;
 
        client = preview->priv->client;
        comp = preview->priv->comp;
@@ -210,18 +235,23 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        g_string_append (buffer, HTML_HEADER);
        g_string_append (buffer, "<body class=\"-e-web-view-background-color -e-web-view-text-color\">");
 
+       markup = g_markup_escape_text (text.value ? text.value : _("Untitled"), -1);
        if (text.value)
-               g_string_append_printf (buffer, "<h2>%s</h2>", text.value);
+               g_string_append_printf (buffer, "<h2>%s</h2>", markup);
        else
-               g_string_append_printf (buffer, "<h2><i>%s</i></h2>",_("Untitled"));
+               g_string_append_printf (buffer, "<h2><i>%s</i></h2>", markup);
+       g_free (markup);
 
        g_string_append (buffer, "<table border=\"0\" cellspacing=\"5\">");
 
        /* write icons for the categories */
        string = g_string_new (NULL);
        e_cal_component_get_categories_list (comp, &list);
-       if (list != NULL)
-               g_string_append_printf (buffer, "<tr><th>%s</th><td>", _("Categories:"));
+       if (list != NULL) {
+               markup = g_markup_escape_text (_("Categories:"), -1);
+               g_string_append_printf (buffer, "<tr><th>%s</th><td>", markup);
+               g_free (markup);
+       }
        for (iter = list; iter != NULL; iter = iter->next) {
                const gchar *category = iter->data;
                gchar *icon_file;
@@ -238,7 +268,10 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
                } else {
                        if (iter != list)
                                g_string_append_len (string, ", ", 2);
-                       g_string_append (string, category);
+
+                       markup = g_markup_escape_text (category, -1);
+                       g_string_append (string, markup);
+                       g_free (markup);
                }
 
                g_free (icon_file);
@@ -252,18 +285,13 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
 
        /* write location */
        e_cal_component_get_location (comp, &location);
-       if (location && *location)
-               g_string_append_printf (
-                       buffer, "<tr><th>%s</th><td>%s</td></tr>",
-                       _("Location:"), location);
+       cal_component_preview_add_table_line (buffer, _("Location:"), location);
 
        /* write start date */
        e_cal_component_get_dtstart (comp, &dt);
        if (dt.value != NULL) {
                str = timet_to_str_with_zone (&dt, client, default_zone);
-               g_string_append_printf (
-                       buffer, "<tr><th>%s</th><td>%s</td></tr>",
-                       _("Start Date:"), str);
+               cal_component_preview_add_table_line (buffer, _("Start Date:"), str);
                g_free (str);
        }
        e_cal_component_free_datetime (&dt);
@@ -272,9 +300,7 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        e_cal_component_get_dtend (comp, &dt);
        if (dt.value != NULL) {
                str = timet_to_str_with_zone (&dt, client, default_zone);
-               g_string_append_printf (
-                       buffer,"<tr><th>%s</th><td>%s</td></tr>",
-                       _("End Date:"), str);
+               cal_component_preview_add_table_line (buffer, _("End Date:"), str);
                g_free (str);
        }
        e_cal_component_free_datetime (&dt);
@@ -283,9 +309,7 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        e_cal_component_get_due (comp, &dt);
        if (dt.value != NULL) {
                str = timet_to_str_with_zone (&dt, client, default_zone);
-               g_string_append_printf (
-                       buffer, "<tr><th>%s</th><td>%s</td></tr>",
-                       _("Due Date:"), str);
+               cal_component_preview_add_table_line (buffer, _("Due Date:"), str);
                g_free (str);
        }
        e_cal_component_free_datetime (&dt);
@@ -295,9 +319,7 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
                        calendar_config_get_week_start_day (), E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_NONE);
 
                if (str) {
-                       g_string_append_printf (
-                               buffer, "<tr><th>%s</th><td>%s</td></tr>",
-                               _("Recurs:"), str);
+                       cal_component_preview_add_table_line (buffer, _("Recurs:"), str);
                        g_free (str);
                }
        }
@@ -307,46 +329,37 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        icalprop = icalcomponent_get_first_property (
                icalcomp, ICAL_STATUS_PROPERTY);
        if (icalprop != NULL) {
-               g_string_append_printf (
-                       buffer, "<tr><th>%s</th>",
-                       _("Status:"));
                e_cal_component_get_status (comp, &status);
                switch (status) {
                case ICAL_STATUS_INPROCESS :
-                       str = g_strdup (_("In Progress"));
+                       tmp = _("In Progress");
                        break;
                case ICAL_STATUS_COMPLETED :
-                       str = g_strdup (_("Completed"));
+                       tmp = _("Completed");
                        break;
                case ICAL_STATUS_CANCELLED :
-                       str = g_strdup (_("Cancelled"));
+                       tmp = _("Cancelled");
                        break;
                case ICAL_STATUS_NONE :
                default :
-                       str = g_strdup (_("Not Started"));
+                       tmp = _("Not Started");
                        break;
                }
 
-               g_string_append_printf (buffer, "<td>%s</td></tr>", str);
-               g_free (str);
+               cal_component_preview_add_table_line (buffer, _("Status:"), tmp);
        }
 
        /* write priority */
        e_cal_component_get_priority (comp, &priority_value);
        if (priority_value && *priority_value != 0) {
-               g_string_append_printf (
-                       buffer, "<tr><th>%s</th>",
-                       _("Priority:"));
                if (*priority_value <= 4)
-                       str = g_strdup (_("High"));
+                       tmp = _("High");
                else if (*priority_value == 5)
-                       str = g_strdup (_("Normal"));
+                       tmp = _("Normal");
                else
-                       str = g_strdup (_("Low"));
-
-               g_string_append_printf (buffer, "<td>%s</td></tr>", str);
+                       tmp = _("Low");
 
-               g_free (str);
+               cal_component_preview_add_table_line (buffer, _("Priority:"), tmp);
        }
 
        if (priority_value)
@@ -359,9 +372,9 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        if (list) {
                GSList *node;
 
-               g_string_append_printf (
-                       buffer, "<tr><th>%s</th>",
-                       _("Description:"));
+               markup = g_markup_escape_text (_("Description:"), -1);
+               g_string_append_printf (buffer, "<tr><th>%s</th>", markup);
+               g_free (markup);
 
                g_string_append (buffer, "<td class=\"description\">");
 
@@ -390,7 +403,7 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        /* URL */
        e_cal_component_get_url (comp, &url);
        if (url) {
-               gchar *scheme;
+               gchar *scheme, *header_markup;
                const gchar *href = url;
 
                str = NULL;
@@ -403,10 +416,22 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
 
                g_free (scheme);
 
+               if (strchr (href, '\"')) {
+                       markup = g_markup_escape_text (href, -1);
+                       g_free (str);
+                       str = markup;
+                       href = str;
+               }
+
+               header_markup = g_markup_escape_text (_("Web Page:"), -1);
+               markup = g_markup_escape_text (url, -1);
+
                g_string_append_printf (
                        buffer, "<tr><th>%s</th><td><a href=\"%s\">%s</a></td></tr>",
-                       _("Web Page:"), href, url);
+                       header_markup, href, markup);
 
+               g_free (header_markup);
+               g_free (markup);
                g_free (str);
        }
 


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