[libgdata] gcontact: Fix attribute escaping for GDataGContactLanguage



commit 807ae95cb8d2baac80002c4bb79118f9de2b1e1f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Dec 2 12:17:31 2010 +0000

    gcontact: Fix attribute escaping for GDataGContactLanguage
    
    Helps: bgo#631033

 gdata/gcontact/gdata-gcontact-language.c |    2 +-
 gdata/tests/general.c                    |   32 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/gdata/gcontact/gdata-gcontact-language.c b/gdata/gcontact/gdata-gcontact-language.c
index 78dc773..44a4361 100644
--- a/gdata/gcontact/gdata-gcontact-language.c
+++ b/gdata/gcontact/gdata-gcontact-language.c
@@ -212,7 +212,7 @@ pre_get_xml (GDataParsable *parsable, GString *xml_string)
 	GDataGContactLanguagePrivate *priv = GDATA_GCONTACT_LANGUAGE (parsable)->priv;
 
 	if (priv->code != NULL)
-		g_string_append_printf (xml_string, " code='%s'", priv->code);
+		gdata_parser_string_append_escaped (xml_string, " code='", priv->code, "'");
 	else if (priv->label != NULL)
 		gdata_parser_string_append_escaped (xml_string, " label='", priv->label, "'");
 	else
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 78c7b87..b8f1c09 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -3266,6 +3266,37 @@ test_gcontact_language_error_handling (void)
 }
 
 static void
+test_gcontact_language_escaping (void)
+{
+	GDataGContactLanguage *language;
+	gchar *xml;
+
+	/* Test with code */
+	language = gdata_gcontact_language_new ("<code>", NULL);
+
+	/* Check the outputted XML is escaped properly */
+	xml = gdata_parsable_get_xml (GDATA_PARSABLE (language));
+	g_assert_cmpstr (xml, ==,
+	                 "<?xml version='1.0' encoding='UTF-8'?>"
+	                 "<gContact:language xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
+				"code='&lt;code&gt;'/>");
+	g_free (xml);
+	g_object_unref (language);
+
+	/* Test with label */
+	language = gdata_gcontact_language_new (NULL, "Label & stuff");
+
+	/* Check the outputted XML is escaped properly */
+	xml = gdata_parsable_get_xml (GDATA_PARSABLE (language));
+	g_assert_cmpstr (xml, ==,
+	                 "<?xml version='1.0' encoding='UTF-8'?>"
+	                 "<gContact:language xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
+				"label='Label &amp; stuff'/>");
+	g_free (xml);
+	g_object_unref (language);
+}
+
+static void
 test_gcontact_relation (void)
 {
 	GDataGContactRelation *relation, *relation2;
@@ -3509,6 +3540,7 @@ main (int argc, char *argv[])
 	g_test_add_func ("/gcontact/jot/escaping", test_gcontact_jot_escaping);
 	g_test_add_func ("/gcontact/language", test_gcontact_language);
 	g_test_add_func ("/gcontact/language/error_handling", test_gcontact_language_error_handling);
+	g_test_add_func ("/gcontact/language/escaping", test_gcontact_language_escaping);
 	g_test_add_func ("/gcontact/relation", test_gcontact_relation);
 	g_test_add_func ("/gcontact/relation/error_handling", test_gcontact_relation_error_handling);
 	g_test_add_func ("/gcontact/website", test_gcontact_website);



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