[libgdata] gd: Fix attribute escaping for GDataGDIMAddress



commit f37944aa5dabe5cb6c72002384ddb60416089738
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Sep 30 17:23:46 2010 +0100

    gd: Fix attribute escaping for GDataGDIMAddress

 gdata/gd/gdata-gd-im-address.c |    7 +++----
 gdata/tests/general.c          |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-im-address.c b/gdata/gd/gdata-gd-im-address.c
index 624d7e6..3ded135 100644
--- a/gdata/gd/gdata-gd-im-address.c
+++ b/gdata/gd/gdata-gd-im-address.c
@@ -293,13 +293,12 @@ pre_get_xml (GDataParsable *parsable, GString *xml_string)
 {
 	GDataGDIMAddressPrivate *priv = GDATA_GD_IM_ADDRESS (parsable)->priv;
 
+	gdata_parser_string_append_escaped (xml_string, " address='", priv->address, "'");
 	if (priv->protocol != NULL)
-		g_string_append_printf (xml_string, " address='%s' protocol='%s'", priv->address, priv->protocol);
-	else
-		g_string_append_printf (xml_string, " address='%s'", priv->address);
+		gdata_parser_string_append_escaped (xml_string, " protocol='", priv->protocol, "'");
 
 	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, "'");
 
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 1d74eb0..03fcee0 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -1565,6 +1565,26 @@ test_gd_im_address (void)
 }
 
 static void
+test_gd_im_address_escaping (void)
+{
+	GDataGDIMAddress *im;
+	gchar *xml;
+
+	im = gdata_gd_im_address_new ("Fubar <fubar gmail com>", GDATA_GD_IM_PROTOCOL_GOOGLE_TALK "?foo&bar", GDATA_GD_IM_ADDRESS_HOME "?foo&bar",
+	                              "Personal & Private", TRUE);
+
+	/* Check the outputted XML is escaped properly */
+	xml = gdata_parsable_get_xml (GDATA_PARSABLE (im));
+	g_assert_cmpstr (xml, ==,
+	                 "<?xml version='1.0' encoding='UTF-8'?>"
+	                 "<gd:im xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
+	                        "address='Fubar &lt;fubar gmail com&gt;' protocol='http://schemas.google.com/g/2005#GOOGLE_TALK?foo&amp;bar' "
+	                        "rel='http://schemas.google.com/g/2005#home?foo&amp;bar' label='Personal &amp; Private' primary='true'/>");
+	g_free (xml);
+	g_object_unref (im);
+}
+
+static void
 test_gd_name (void)
 {
 	GDataGDName *name, *name2;
@@ -3104,6 +3124,7 @@ main (int argc, char *argv[])
 	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/im_address/escaping", test_gd_im_address_escaping);
 	g_test_add_func ("/gd/name", test_gd_name);
 	g_test_add_func ("/gd/organization", test_gd_organization);
 	g_test_add_func ("/gd/phone_number", test_gd_phone_number);



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