[libgdata] picasaweb: Fix attribute escaping for GDataPicasaWebAlbum



commit 58880acd7ad007d2fee1f2278ffbb78f7b7bea02
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Dec 2 17:06:00 2010 +0000

    picasaweb: Fix attribute escaping for GDataPicasaWebAlbum
    
    Helps: bgo#631033

 gdata/services/picasaweb/gdata-picasaweb-album.c |    3 +-
 gdata/tests/picasaweb.c                          |   45 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/gdata/services/picasaweb/gdata-picasaweb-album.c b/gdata/services/picasaweb/gdata-picasaweb-album.c
index d1cd344..132eba9 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-album.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-album.c
@@ -765,7 +765,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 
 	/* Add all the album-specific XML */
 	if (priv->album_id != NULL)
-		g_string_append_printf (xml_string, "<gphoto:id>%s</gphoto:id>", priv->album_id);
+		gdata_parser_string_append_escaped (xml_string, "<gphoto:id>", priv->album_id, "</gphoto:id>");
 
 	if (priv->location != NULL)
 		gdata_parser_string_append_escaped (xml_string, "<gphoto:location>", priv->location, "</gphoto:location>");
@@ -803,7 +803,6 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 	/* TODO:
 	 * - Finish supporting all tags
 	 * - Check all tags here are valid for insertions and updates
-	 * - Check things are escaped (or not) as appropriate
 	 * - add GML support
 	 */
 }
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index 849cbf9..90149b4 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -1469,6 +1469,49 @@ test_album_new (void)
 }
 
 static void
+test_album_escaping (void)
+{
+	GDataPicasaWebAlbum *album;
+	gchar *xml;
+	GError *error = NULL;
+	const gchar * const tags[] = { "<tag1>", "tag2 & stuff, things", NULL };
+
+	/* We have to create the album this way so that the album ID is set */
+	album = GDATA_PICASAWEB_ALBUM (gdata_parsable_new_from_xml (GDATA_TYPE_PICASAWEB_ALBUM,
+		"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007'>"
+			"<title type='text'></title>"
+			"<category term='http://schemas.google.com/photos/2007#album' scheme='http://schemas.google.com/g/2005#kind'/>"
+			"<gphoto:id>&lt;id&gt;</gphoto:id>"
+		"</entry>", -1, &error));
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_PICASAWEB_ALBUM (album));
+	g_clear_error (&error);
+
+	/* Set other properties */
+	gdata_picasaweb_album_set_location (album, "Everywhere & nowhere");
+	gdata_picasaweb_album_set_tags (album, tags);
+
+	/* Check the outputted XML is escaped properly */
+	xml = gdata_parsable_get_xml (GDATA_PARSABLE (album));
+	g_assert_cmpstr (xml, ==,
+	                 "<?xml version='1.0' encoding='UTF-8'?>"
+	                 "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007' "
+	                        "xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' "
+	                        "xmlns:gml='http://www.opengis.net/gml' xmlns:app='http://www.w3.org/2007/app' "
+	                        "xmlns:georss='http://www.georss.org/georss'>"
+				"<title type='text'></title>"
+				"<category term='http://schemas.google.com/photos/2007#album' scheme='http://schemas.google.com/g/2005#kind'/>"
+				"<gphoto:id>&lt;id&gt;</gphoto:id>"
+				"<gphoto:location>Everywhere &amp; nowhere</gphoto:location>"
+				"<gphoto:access>private</gphoto:access>"
+				"<gphoto:commentingEnabled>false</gphoto:commentingEnabled>"
+				"<media:group><media:keywords>&lt;tag1&gt;,tag2 &amp; stuff%2C things</media:keywords></media:group>"
+	                 "</entry>");
+	g_free (xml);
+	g_object_unref (album);
+}
+
+static void
 test_query_etag (void)
 {
 	GDataPicasaWebQuery *query = gdata_picasaweb_query_new (NULL);
@@ -1540,6 +1583,8 @@ main (int argc, char *argv[])
 	}
 
 	g_test_add_func ("/picasaweb/album/new", test_album_new);
+	g_test_add_func ("/picasaweb/album/escaping", test_album_escaping);
+
 	g_test_add_func ("/picasaweb/query/etag", test_query_etag);
 
 	retval = g_test_run ();



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