[libgdata] picasaweb: Fix attribute escaping for GDataPicasaWebFile



commit a4dae63676259caa67b48f0cefec4522c7516d56
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Dec 2 17:19:27 2010 +0000

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

 gdata/services/picasaweb/gdata-picasaweb-file.c |    7 +--
 gdata/tests/picasaweb.c                         |   55 +++++++++++++++++++++++
 2 files changed, 58 insertions(+), 4 deletions(-)
---
diff --git a/gdata/services/picasaweb/gdata-picasaweb-file.c b/gdata/services/picasaweb/gdata-picasaweb-file.c
index c3a9a3b..111e414 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-file.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-file.c
@@ -1009,16 +1009,16 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 
 	/* Add all the PicasaWeb-specific XML */
 	if (priv->file_id != NULL)
-		g_string_append_printf (xml_string, "<gphoto:id>%s</gphoto:id>", priv->file_id);
+		gdata_parser_string_append_escaped (xml_string, "<gphoto:id>", priv->file_id, "</gphoto:id>");
 
 	if (priv->version != NULL)
-		g_string_append_printf (xml_string, "<gphoto:version>%s</gphoto:version>", priv->version);
+		gdata_parser_string_append_escaped (xml_string, "<gphoto:version>", priv->version, "</gphoto:version>");
 
 	g_string_append_printf (xml_string, "<gphoto:position>%s</gphoto:position>",
 	                        g_ascii_dtostr (ascii_double_str, sizeof (ascii_double_str), priv->position));
 
 	if (priv->album_id != NULL)
-		g_string_append_printf (xml_string, "<gphoto:albumid>%s</gphoto:albumid>", priv->album_id);
+		gdata_parser_string_append_escaped (xml_string, "<gphoto:albumid>", priv->album_id, "</gphoto:albumid>");
 
 	if (priv->client != NULL)
 		gdata_parser_string_append_escaped (xml_string, "<gphoto:client>", priv->client, "</gphoto:client>");
@@ -1051,7 +1051,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
 	 */
 }
 
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index 90149b4..67029c6 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -1512,6 +1512,60 @@ test_album_escaping (void)
 }
 
 static void
+test_file_escaping (void)
+{
+	GDataPicasaWebFile *file;
+	gchar *xml;
+	GError *error = NULL;
+	const gchar * const tags[] = { "<tag1>", "tag2 & stuff, things", NULL };
+
+	/* We have to create the file this way so that the photo ID and version are set */
+	file = GDATA_PICASAWEB_FILE (gdata_parsable_new_from_xml (GDATA_TYPE_PICASAWEB_FILE,
+		"<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#photo' scheme='http://schemas.google.com/g/2005#kind'/>"
+			"<gphoto:id>&lt;id&gt;</gphoto:id>"
+			"<gphoto:imageVersion>&lt;version&gt;</gphoto:imageVersion>"
+		"</entry>", -1, &error));
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_PICASAWEB_FILE (file));
+	g_clear_error (&error);
+
+	/* Set other properties */
+	gdata_picasaweb_file_set_album_id (file, "http://foo.com?foo&bar";);
+	gdata_picasaweb_file_set_client (file, "GIMP & Co.");
+	gdata_picasaweb_file_set_checksum (file, "<checksum>");
+	gdata_picasaweb_file_set_tags (file, tags);
+	gdata_picasaweb_file_set_caption (file, "Caption & stuff.");
+
+	/* Check the outputted XML is escaped properly */
+	xml = gdata_parsable_get_xml (GDATA_PARSABLE (file));
+	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:exif='http://schemas.google.com/photos/exif/2007' xmlns:app='http://www.w3.org/2007/app' "
+	                        "xmlns:georss='http://www.georss.org/georss' xmlns:gml='http://www.opengis.net/gml'>"
+				"<title type='text'></title>"
+				"<summary type='text'>Caption &amp; stuff.</summary>"
+				"<category term='http://schemas.google.com/photos/2007#photo' scheme='http://schemas.google.com/g/2005#kind'/>"
+				"<gphoto:id>&lt;id&gt;</gphoto:id>"
+				"<gphoto:version>&lt;version&gt;</gphoto:version>"
+				"<gphoto:position>0</gphoto:position>"
+				"<gphoto:albumid>http://foo.com?foo&amp;bar</gphoto:albumid>"
+				"<gphoto:client>GIMP &amp; Co.</gphoto:client>"
+				"<gphoto:checksum>&lt;checksum&gt;</gphoto:checksum>"
+				"<gphoto:commentingEnabled>true</gphoto:commentingEnabled>"
+				"<media:group>"
+					"<media:description type='plain'>Caption &amp; stuff.</media:description>"
+					"<media:keywords>&lt;tag1&gt;,tag2 &amp; stuff%2C things</media:keywords>"
+				"</media:group>"
+	                 "</entry>");
+	g_free (xml);
+	g_object_unref (file);
+}
+
+static void
 test_query_etag (void)
 {
 	GDataPicasaWebQuery *query = gdata_picasaweb_query_new (NULL);
@@ -1584,6 +1638,7 @@ 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/file/escaping", test_file_escaping);
 
 	g_test_add_func ("/picasaweb/query/etag", test_query_etag);
 



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