[libgdata] gcontact: Fix attribute escaping for GDataGContactRelation
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] gcontact: Fix attribute escaping for GDataGContactRelation
- Date: Thu, 2 Dec 2010 12:24:27 +0000 (UTC)
commit 91c1bc17304dcde4356652ac2ed2552961e34d36
Author: Philip Withnall <philip tecnocode co uk>
Date: Thu Dec 2 12:20:40 2010 +0000
gcontact: Fix attribute escaping for GDataGContactRelation
Helps: bgo#631033
gdata/gcontact/gdata-gcontact-relation.c | 2 +-
gdata/tests/general.c | 32 ++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/gdata/gcontact/gdata-gcontact-relation.c b/gdata/gcontact/gdata-gcontact-relation.c
index 19ac993..2cfcac5 100644
--- a/gdata/gcontact/gdata-gcontact-relation.c
+++ b/gdata/gcontact/gdata-gcontact-relation.c
@@ -243,7 +243,7 @@ pre_get_xml (GDataParsable *parsable, GString *xml_string)
GDataGContactRelationPrivate *priv = GDATA_GCONTACT_RELATION (parsable)->priv;
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, "'");
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 b8f1c09..84e7039 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -3374,6 +3374,37 @@ test_gcontact_relation_error_handling (void)
}
static void
+test_gcontact_relation_escaping (void)
+{
+ GDataGContactRelation *relation;
+ gchar *xml;
+
+ /* Test with rel */
+ relation = gdata_gcontact_relation_new ("First & Last Name", "http://foo.com?foo&relation=bar", NULL);
+
+ /* Check the outputted XML is escaped properly */
+ xml = gdata_parsable_get_xml (GDATA_PARSABLE (relation));
+ g_assert_cmpstr (xml, ==,
+ "<?xml version='1.0' encoding='UTF-8'?>"
+ "<gContact:relation xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
+ "rel='http://foo.com?foo&relation=bar'>First & Last Name</gContact:relation>");
+ g_free (xml);
+ g_object_unref (relation);
+
+ /* Test with label */
+ relation = gdata_gcontact_relation_new ("First & Last Name", NULL, "Label & stuff");
+
+ /* Check the outputted XML is escaped properly */
+ xml = gdata_parsable_get_xml (GDATA_PARSABLE (relation));
+ g_assert_cmpstr (xml, ==,
+ "<?xml version='1.0' encoding='UTF-8'?>"
+ "<gContact:relation xmlns='http://www.w3.org/2005/Atom' xmlns:gContact='http://schemas.google.com/contact/2008' "
+ "label='Label & stuff'>First & Last Name</gContact:relation>");
+ g_free (xml);
+ g_object_unref (relation);
+}
+
+static void
test_gcontact_website (void)
{
GDataGContactWebsite *website, *website2;
@@ -3543,6 +3574,7 @@ main (int argc, char *argv[])
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/relation/escaping", test_gcontact_relation_escaping);
g_test_add_func ("/gcontact/website", test_gcontact_website);
g_test_add_func ("/gcontact/website/error_handling", test_gcontact_website_error_handling);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]