evolution r36517 - branches/gnome-2-24/plugins/itip-formatter



Author: mcrha
Date: Wed Oct  1 07:53:55 2008
New Revision: 36517
URL: http://svn.gnome.org/viewvc/evolution?rev=36517&view=rev

Log:
2008-10-01  Milan Crha  <mcrha redhat com>

	** Fix for bug #519491

	* itip-view.c: (ensure_utf8), (itip_view_set_organizer),
	(itip_view_set_organizer_sentby), (itip_view_set_attendee),
	(itip_view_set_attendee_sentby), (itip_view_set_proxy),
	(itip_view_set_delegator), (itip_view_set_summary),
	(itip_view_set_location), (itip_view_set_status),
	(itip_view_set_comment), (itip_view_set_description),
	(itip_view_add_upper_info_item), (itip_view_add_lower_info_item):
	Convert texts to valid UTF-8 texts before passing them to Gtk+
	functions which requires that.



Modified:
   branches/gnome-2-24/plugins/itip-formatter/ChangeLog
   branches/gnome-2-24/plugins/itip-formatter/itip-view.c

Modified: branches/gnome-2-24/plugins/itip-formatter/itip-view.c
==============================================================================
--- branches/gnome-2-24/plugins/itip-formatter/itip-view.c	(original)
+++ branches/gnome-2-24/plugins/itip-formatter/itip-view.c	Wed Oct  1 07:53:55 2008
@@ -1194,6 +1194,24 @@
 	return priv->type;
 }
 
+/* ensures the returned text will be valid UTF-8 text, thus gtk functions expecting
+   only valid UTF-8 texts will not crash. Returned pointer should be freed with g_free. */
+static gchar *
+ensure_utf8 (const char *text)
+{
+	gchar *res = g_strdup (text), *p;
+
+	if (!text)
+		return res;
+
+	p = res;
+	while (!g_utf8_validate (p, -1, (const gchar **) &p)) {
+		/* make all invalid characters appear as question marks */
+		*p = '?';
+	}
+
+	return res;
+}
 
 void
 itip_view_set_organizer (ItipView *view, const char *organizer)
@@ -1208,7 +1226,7 @@
 	if (priv->organizer)
 		g_free (priv->organizer);
 
-	priv->organizer = g_strdup (organizer);
+	priv->organizer = ensure_utf8 (organizer);
 
 	set_sender_text (view);
 }
@@ -1239,7 +1257,7 @@
 	if (priv->organizer_sentby)
 		g_free (priv->organizer_sentby);
 
-	priv->organizer_sentby = g_strdup (sentby);
+	priv->organizer_sentby = ensure_utf8 (sentby);
 
 	set_sender_text (view);
 }
@@ -1270,7 +1288,7 @@
 	if (priv->attendee)
 		g_free (priv->attendee);
 
-	priv->attendee = g_strdup (attendee);
+	priv->attendee = ensure_utf8 (attendee);
 
 	set_sender_text (view);
 }
@@ -1301,7 +1319,7 @@
 	if (priv->attendee_sentby)
 		g_free (priv->attendee_sentby);
 
-	priv->attendee_sentby = g_strdup (sentby);
+	priv->attendee_sentby = ensure_utf8 (sentby);
 
 	set_sender_text (view);
 }
@@ -1332,7 +1350,7 @@
 	if (priv->proxy)
 		g_free (priv->proxy);
 
-	priv->proxy = g_strdup (proxy);
+	priv->proxy = ensure_utf8 (proxy);
 
 	set_sender_text (view);
 }
@@ -1363,7 +1381,7 @@
 	if (priv->delegator)
 		g_free (priv->delegator);
 
-	priv->delegator = g_strdup (delegator);
+	priv->delegator = ensure_utf8 (delegator);
 
 	set_sender_text (view);
 }
@@ -1394,7 +1412,7 @@
 	if (priv->summary)
 		g_free (priv->summary);
 
-	priv->summary = summary ? g_strstrip (g_strdup (summary)) : NULL;
+	priv->summary = summary ? g_strstrip (ensure_utf8 (summary)) : NULL;
 
 	set_summary_text (view);
 }
@@ -1425,7 +1443,7 @@
 	if (priv->location)
 		g_free (priv->location);
 
-	priv->location = location ? g_strstrip (g_strdup (location)) : NULL;
+	priv->location = location ? g_strstrip (ensure_utf8 (location)) : NULL;
 
 	set_location_text (view);
 }
@@ -1456,7 +1474,7 @@
 	if (priv->status)
 		g_free (priv->status);
 
-	priv->status = status ? g_strstrip (g_strdup (status)) : NULL;
+	priv->status = status ? g_strstrip (ensure_utf8 (status)) : NULL;
 
 	set_status_text (view);
 }
@@ -1487,7 +1505,7 @@
 	if (priv->comment)
 		g_free (priv->comment);
 
-	priv->comment = comment ? g_strstrip (g_strdup (comment)) : NULL;
+	priv->comment = comment ? g_strstrip (ensure_utf8 (comment)) : NULL;
 
 	set_comment_text (view);
 }
@@ -1519,7 +1537,7 @@
 	if (priv->description)
 		g_free (priv->description);
 
-	priv->description = description ? g_strstrip (g_strdup (description)) : NULL;
+	priv->description = description ? g_strstrip (ensure_utf8 (description)) : NULL;
 
 	set_description_text (view);
 }
@@ -1624,7 +1642,7 @@
 	item = g_new0 (ItipViewInfoItem, 1);
 
 	item->type = type;
-	item->message = g_strdup (message);
+	item->message = ensure_utf8 (message);
 	item->id = priv->next_info_item_id++;
 
 	priv->upper_info_items = g_slist_append (priv->upper_info_items, item);
@@ -1719,7 +1737,7 @@
 	item = g_new0 (ItipViewInfoItem, 1);
 
 	item->type = type;
-	item->message = g_strdup (message);
+	item->message = ensure_utf8 (message);
 	item->id = priv->next_info_item_id++;
 
 	priv->lower_info_items = g_slist_append (priv->lower_info_items, item);



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