[evolution] I#583 - Sanitize \r\n\t in iCalendar component Summary
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#583 - Sanitize \r\n\t in iCalendar component Summary
- Date: Tue, 20 Aug 2019 16:55:07 +0000 (UTC)
commit b625bcc4be4b5b46fb9442788fdc9c28b5f00c68
Author: Milan Crha <mcrha redhat com>
Date: Tue Aug 20 18:54:40 2019 +0200
I#583 - Sanitize \r\n\t in iCalendar component Summary
Closes https://gitlab.gnome.org/GNOME/evolution/issues/583
src/calendar/gui/e-cal-model.c | 28 +++++++++++++++++++++++++
src/calendar/gui/e-cal-model.h | 3 +++
src/calendar/gui/e-calendar-view.c | 11 ++++++----
src/calendar/gui/e-comp-editor-property-parts.c | 16 ++++++++++++++
4 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/src/calendar/gui/e-cal-model.c b/src/calendar/gui/e-cal-model.c
index ed23659d5a..900dae8f84 100644
--- a/src/calendar/gui/e-cal-model.c
+++ b/src/calendar/gui/e-cal-model.c
@@ -403,6 +403,8 @@ get_summary (ECalModelComponent *comp_data)
if (!res)
res = g_strdup ("");
+ e_cal_model_until_sanitize_text_value (res, -1);
+
return res;
}
@@ -4409,3 +4411,29 @@ e_cal_model_util_get_datetime_value (ECalModel *model,
return value;
}
+
+/* Removes unneeded characters from the 'value'.
+ It modifies the 'value' inline. */
+void
+e_cal_model_until_sanitize_text_value (gchar *value,
+ gint value_length)
+{
+ if (value && (value_length > 0 || value_length == -1) && *value) {
+ gchar *ptr, *pos;
+
+ for (ptr = value, pos = value; (value_length > 0 || value_length == -1) && *ptr; ptr++,
pos++) {
+ if (*ptr == '\r')
+ pos--;
+ else if (*ptr == '\n' || *ptr == '\t')
+ *pos = ' ';
+ else if (pos != ptr)
+ *pos = *ptr;
+
+ if (value_length != -1)
+ value_length--;
+ }
+
+ if (pos < ptr)
+ *pos = '\0';
+ }
+}
diff --git a/src/calendar/gui/e-cal-model.h b/src/calendar/gui/e-cal-model.h
index 0b7d90d900..18ef8f47a4 100644
--- a/src/calendar/gui/e-cal-model.h
+++ b/src/calendar/gui/e-cal-model.h
@@ -419,6 +419,9 @@ ECellDateEditValue *
ECalModelComponent *comp_data,
ICalPropertyKind kind,
ICalTime * (*get_time_func) (ICalProperty *prop));
+void e_cal_model_until_sanitize_text_value
+ (gchar *value,
+ gint value_length);
G_END_DECLS
diff --git a/src/calendar/gui/e-calendar-view.c b/src/calendar/gui/e-calendar-view.c
index 11573df1de..0b8ce105ca 100644
--- a/src/calendar/gui/e-calendar-view.c
+++ b/src/calendar/gui/e-calendar-view.c
@@ -2088,6 +2088,7 @@ gchar *
e_calendar_view_dup_component_summary (ICalComponent *icomp)
{
const gchar *summary;
+ gchar *res = NULL;
g_return_val_if_fail (icomp != NULL, NULL);
@@ -2102,7 +2103,6 @@ e_calendar_view_dup_component_summary (ICalComponent *icomp)
if (since_year_str) {
ICalTime *dtstart;
gint since_year;
- gchar *res = NULL;
since_year = atoi (since_year_str);
@@ -2119,12 +2119,15 @@ e_calendar_view_dup_component_summary (ICalComponent *icomp)
g_clear_object (&dtstart);
g_free (since_year_str);
-
- return res ? res : g_strdup (summary);
}
}
- return g_strdup (summary);
+ if (!res)
+ res = g_strdup (summary ? summary : "");
+
+ e_cal_model_until_sanitize_text_value (res, -1);
+
+ return res;
}
/* A callback for e_cal_ops_create_component(), whose @user_data is an ECalendarView instance */
diff --git a/src/calendar/gui/e-comp-editor-property-parts.c b/src/calendar/gui/e-comp-editor-property-parts.c
index 53e106859f..82d35c1328 100644
--- a/src/calendar/gui/e-comp-editor-property-parts.c
+++ b/src/calendar/gui/e-comp-editor-property-parts.c
@@ -25,6 +25,7 @@
#include "calendar-config.h"
#include "comp-util.h"
+#include "e-cal-model.h"
#include "e-timezone-entry.h"
#include "e-comp-editor-property-part.h"
@@ -56,6 +57,16 @@ GType e_comp_editor_property_part_summary_get_type (void) G_GNUC_CONST;
G_DEFINE_TYPE (ECompEditorPropertyPartSummary, e_comp_editor_property_part_summary,
E_TYPE_COMP_EDITOR_PROPERTY_PART_STRING)
+static void
+ecepp_summary_insert_text_cb (GtkEditable *editable,
+ gchar *new_text,
+ gint new_text_length,
+ gpointer position,
+ gpointer user_data)
+{
+ e_cal_model_until_sanitize_text_value (new_text, new_text_length);
+}
+
static void
ecepp_summary_create_widgets (ECompEditorPropertyPart *property_part,
GtkWidget **out_label_widget,
@@ -88,6 +99,11 @@ ecepp_summary_create_widgets (ECompEditorPropertyPart *property_part,
NULL);
gtk_widget_show (*out_label_widget);
+
+ if (GTK_IS_EDITABLE (*out_edit_widget)) {
+ g_signal_connect (*out_edit_widget, "insert-text",
+ G_CALLBACK (ecepp_summary_insert_text_cb), NULL);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]