[libgdata] gd: Fix attribute escaping for GDataGDEmailAddress



commit 68584f8c6a3ae3564919b02343dcbaf2282a3c72
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 aaf6821..d1ef2bf 100644
--- a/gdata/gd/gdata-gd-email-address.c
+++ b/gdata/gd/gdata-gd-email-address.c
@@ -289,9 +289,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 d863c4c..1d74eb0 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -1479,6 +1479,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>", GDATA_GD_EMAIL_ADDRESS_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;
@@ -3080,6 +3102,7 @@ main (int argc, char *argv[])
 	g_test_add_func ("/app/categories", test_app_categories);
 
 	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]