[libgdata/libgdata-0-6] gd: Fix attribute escaping for GDataGDEmailAddress



commit 16fe5f793ea94d47966d3ec67a36c1476196e009
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Sep 30 17:10:12 2010 +0100

    gd: Fix attribute escaping for GDataGDEmailAddress
    
    Add a test case for it too. Closes: bgo#630350

 gdata/gd/gdata-gd-email-address.c |    4 ++--
 gdata/tests/general.c             |   23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-email-address.c b/gdata/gd/gdata-gd-email-address.c
index 745d2e5..699e086 100644
--- a/gdata/gd/gdata-gd-email-address.c
+++ b/gdata/gd/gdata-gd-email-address.c
@@ -283,9 +283,9 @@ pre_get_xml (GDataParsable *parsable, GString *xml_string)
 {
 	GDataGDEmailAddressPrivate *priv = GDATA_GD_EMAIL_ADDRESS (parsable)->priv;
 
-	g_string_append_printf (xml_string, " address='%s'", priv->address);
+	gdata_parser_string_append_escaped (xml_string, " address='", priv->address, "'");
 	if (priv->relation_type != NULL)
-		g_string_append_printf (xml_string, " rel='%s'", priv->relation_type);
+		gdata_parser_string_append_escaped (xml_string, " rel='", priv->relation_type, "'");
 	if (priv->label != NULL)
 		gdata_parser_string_append_escaped (xml_string, " label='", priv->label, "'");
 	if (priv->display_name != NULL)
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 8526503..61ad24f 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -1332,6 +1332,28 @@ test_gd_email_address (void)
 }
 
 static void
+test_gd_email_address_escaping (void)
+{
+	GDataGDEmailAddress *email;
+	gchar *xml;
+
+	g_test_bug ("630350");
+
+	email = gdata_gd_email_address_new ("Fubar <fubar gmail com>", "http://schemas.google.com/g/2005#home?foo&bar";, "Personal & Private", TRUE);
+	gdata_gd_email_address_set_display_name (email, "<John Smith>");
+
+	/* Check the outputted XML is escaped properly */
+	xml = gdata_parsable_get_xml (GDATA_PARSABLE (email));
+	g_assert_cmpstr (xml, ==,
+	                 "<?xml version='1.0' encoding='UTF-8'?>"
+	                 "<gd:email xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
+	                           "address='Fubar &lt;fubar gmail com&gt;' rel='http://schemas.google.com/g/2005#home?foo&amp;bar' "
+	                           "label='Personal &amp; Private' displayName='&lt;John Smith&gt;' primary='true'/>");
+	g_free (xml);
+	g_object_unref (email);
+}
+
+static void
 test_gd_im_address (void)
 {
 	GDataGDIMAddress *im, *im2;
@@ -2376,6 +2398,7 @@ main (int argc, char *argv[])
 	g_test_add_func ("/atom/link/error_handling", test_atom_link_error_handling);
 
 	g_test_add_func ("/gd/email_address", test_gd_email_address);
+	g_test_add_func ("/gd/email_address/escaping", test_gd_email_address_escaping);
 	g_test_add_func ("/gd/im_address", test_gd_im_address);
 	g_test_add_func ("/gd/name", test_gd_name);
 	g_test_add_func ("/gd/organization", test_gd_organization);



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