[libgdata] Properly encode Unicode characters in query URIs



commit 84764e2042a8c51dcff4eccb4dd41e373302f42e
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Nov 22 16:19:22 2009 +0000

    Properly encode Unicode characters in query URIs
    
    Previously, Unicode characters would just be left in query URIs
    unchanged. Google's servers don't like this, and tend to return empty
    result sets (but without errors), so we should escape Unicode characters
    too. See: bgo#602497

 gdata/gdata-access-handler.c                     |    4 +-
 gdata/gdata-query.c                              |    8 ++--
 gdata/services/calendar/gdata-calendar-query.c   |    6 ++--
 gdata/services/contacts/gdata-contacts-query.c   |    6 ++--
 gdata/services/documents/gdata-documents-query.c |   12 ++++----
 gdata/services/picasaweb/gdata-picasaweb-query.c |    4 +-
 gdata/services/youtube/gdata-youtube-query.c     |    6 ++--
 gdata/tests/general.c                            |   34 +++++++++++++++++++--
 8 files changed, 53 insertions(+), 27 deletions(-)
---
diff --git a/gdata/gdata-access-handler.c b/gdata/gdata-access-handler.c
index 9ed06b5..8bc9048 100644
--- a/gdata/gdata-access-handler.c
+++ b/gdata/gdata-access-handler.c
@@ -245,10 +245,10 @@ get_soup_message (GDataAccessHandler *access_handler, GDataAccessRule *rule, con
 
 	uri_string = g_string_sized_new (strlen (gdata_link_get_uri (link)) + 30);
 	g_string_append_printf (uri_string, "%s/", gdata_link_get_uri (link));
-	g_string_append_uri_escaped (uri_string, scope_type, NULL, TRUE);
+	g_string_append_uri_escaped (uri_string, scope_type, NULL, FALSE);
 	if (scope_value != NULL) {
 		g_string_append (uri_string, "%3A");
-		g_string_append_uri_escaped (uri_string, scope_value, NULL, TRUE);
+		g_string_append_uri_escaped (uri_string, scope_value, NULL, FALSE);
 	}
 
 	uri = g_string_free (uri_string, FALSE);
diff --git a/gdata/gdata-query.c b/gdata/gdata-query.c
index 114213c..1e342e7 100644
--- a/gdata/gdata-query.c
+++ b/gdata/gdata-query.c
@@ -426,13 +426,13 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	/* If we've been provided with an entry ID, only append that */
 	if (priv->entry_id != NULL) {
 		g_string_append_c (query_uri, '/');
-		g_string_append_uri_escaped (query_uri, priv->entry_id, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->entry_id, NULL, FALSE);
 		return;
 	}
 
 	if (priv->categories != NULL) {
 		g_string_append (query_uri, "/-/");
-		g_string_append_uri_escaped (query_uri, priv->categories, "/", TRUE);
+		g_string_append_uri_escaped (query_uri, priv->categories, "/", FALSE);
 	}
 
 	/* If that's it, return */
@@ -443,13 +443,13 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->q != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "q=");
-		g_string_append_uri_escaped (query_uri, priv->q, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->q, NULL, FALSE);
 	}
 
 	if (priv->author != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "author=");
-		g_string_append_uri_escaped (query_uri, priv->author, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->author, NULL, FALSE);
 	}
 
 	if (priv->updated_min.tv_sec != 0 || priv->updated_min.tv_usec != 0) {
diff --git a/gdata/services/calendar/gdata-calendar-query.c b/gdata/services/calendar/gdata-calendar-query.c
index 99f10e0..3be47f7 100644
--- a/gdata/services/calendar/gdata-calendar-query.c
+++ b/gdata/services/calendar/gdata-calendar-query.c
@@ -318,7 +318,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->order_by != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "orderby=");
-		g_string_append_uri_escaped (query_uri, priv->order_by, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->order_by, NULL, FALSE);
 	}
 
 	if (priv->recurrence_expansion_start.tv_sec != 0 || priv->recurrence_expansion_start.tv_usec != 0) {
@@ -350,7 +350,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->sort_order != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "sortorder=");
-		g_string_append_uri_escaped (query_uri, priv->sort_order, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->sort_order, NULL, FALSE);
 	}
 
 	if (priv->start_min.tv_sec != 0 || priv->start_min.tv_usec != 0) {
@@ -376,7 +376,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->timezone != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "ctz=");
-		g_string_append_uri_escaped (query_uri, priv->timezone, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->timezone, NULL, FALSE);
 	}
 }
 
diff --git a/gdata/services/contacts/gdata-contacts-query.c b/gdata/services/contacts/gdata-contacts-query.c
index 5e421d0..e092090 100644
--- a/gdata/services/contacts/gdata-contacts-query.c
+++ b/gdata/services/contacts/gdata-contacts-query.c
@@ -212,7 +212,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->order_by != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "orderby=");
-		g_string_append_uri_escaped (query_uri, priv->order_by, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->order_by, NULL, FALSE);
 	}
 
 	APPEND_SEP
@@ -224,13 +224,13 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->sort_order != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "sortorder=");
-		g_string_append_uri_escaped (query_uri, priv->sort_order, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->sort_order, NULL, FALSE);
 	}
 
 	if (priv->group != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "group=");
-		g_string_append_uri_escaped (query_uri, priv->group, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->group, NULL, FALSE);
 	}
 }
 
diff --git a/gdata/services/documents/gdata-documents-query.c b/gdata/services/documents/gdata-documents-query.c
index 2847765..c6d904d 100644
--- a/gdata/services/documents/gdata-documents-query.c
+++ b/gdata/services/documents/gdata-documents-query.c
@@ -234,7 +234,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 
 	if (entry_id == NULL && priv->folder_id != NULL) {
 		g_string_append (query_uri, "/folder%3A");
-		g_string_append_uri_escaped (query_uri, priv->folder_id, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->folder_id, NULL, FALSE);
 	}
 
 	/* Chain up to the parent class */
@@ -250,10 +250,10 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 		collaborator_address = priv->collaborator_addresses;
 
 		g_string_append (query_uri, "writer=");
-		g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (collaborator_address->data), NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (collaborator_address->data), NULL, FALSE);
 		for (collaborator_address = collaborator_address->next; collaborator_address != NULL; collaborator_address = collaborator_address->next) {
 			g_string_append_c (query_uri, ';');
-			g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (collaborator_address->data), NULL, TRUE);
+			g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (collaborator_address->data), NULL, FALSE);
 		}
 	}
 
@@ -263,17 +263,17 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 		reader_address = priv->reader_addresses;
 
 		g_string_append (query_uri, "reader=");
-		g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (reader_address->data), NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (reader_address->data), NULL, FALSE);
 		for (reader_address = reader_address->next; reader_address != NULL; reader_address = reader_address->next) {
 			g_string_append_c (query_uri, ';');
-			g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (reader_address->data), NULL, TRUE);
+			g_string_append_uri_escaped (query_uri, gdata_gd_email_address_get_address (reader_address->data), NULL, FALSE);
 		}
 	}
 
 	if (priv->title != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "title=");
-		g_string_append_uri_escaped (query_uri, priv->title, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->title, NULL, FALSE);
 		if (priv->exact_title == TRUE)
 			g_string_append (query_uri, "&title-exact=true");
 	}
diff --git a/gdata/services/picasaweb/gdata-picasaweb-query.c b/gdata/services/picasaweb/gdata-picasaweb-query.c
index f1e12ef..da0f3bf 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-query.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-query.c
@@ -271,7 +271,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->tag != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "tag=");
-		g_string_append_uri_escaped (query_uri, priv->tag, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->tag, NULL, FALSE);
 	}
 
 	if (priv->bounding_box.north != priv->bounding_box.south && priv->bounding_box.east != priv->bounding_box.west) {
@@ -288,7 +288,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 	if (priv->location != NULL) {
 		APPEND_SEP
 		g_string_append (query_uri, "l=");
-		g_string_append_uri_escaped (query_uri, priv->location, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->location, NULL, FALSE);
 	}
 }
 
diff --git a/gdata/services/youtube/gdata-youtube-query.c b/gdata/services/youtube/gdata-youtube-query.c
index 50cbe36..dc27729 100644
--- a/gdata/services/youtube/gdata-youtube-query.c
+++ b/gdata/services/youtube/gdata-youtube-query.c
@@ -484,17 +484,17 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
 
 	if (priv->language != NULL) {
 		g_string_append (query_uri, "&lr=");
-		g_string_append_uri_escaped (query_uri, priv->language, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->language, NULL, FALSE);
 	}
 
 	if (priv->order_by != NULL) {
 		g_string_append (query_uri, "&orderby=");
-		g_string_append_uri_escaped (query_uri, priv->order_by, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->order_by, NULL, FALSE);
 	}
 
 	if (priv->restriction != NULL) {
 		g_string_append (query_uri, "&restriction=");
-		g_string_append_uri_escaped (query_uri, priv->restriction, NULL, TRUE);
+		g_string_append_uri_escaped (query_uri, priv->restriction, NULL, FALSE);
 	}
 
 	if (priv->sort_order != GDATA_YOUTUBE_SORT_NONE) {
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index da12886..17eabc2 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -206,28 +206,24 @@ test_query_categories (void)
 	/* AND */
 	gdata_query_set_categories (query, "Fritz/Laurie");
 	query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-
 	g_assert_cmpstr (query_uri, ==, "http://example.com/-/Fritz/Laurie?q=foobar";);
 	g_free (query_uri);
 
 	/* OR */
 	gdata_query_set_categories (query, "Fritz|Laurie");
 	query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-
 	g_assert_cmpstr (query_uri, ==, "http://example.com/-/Fritz%7CLaurie?q=foobar";);
 	g_free (query_uri);
 
 	/* Combination */
 	gdata_query_set_categories (query, "A|-{urn:google.com}B/-C");
 	query_uri = gdata_query_get_query_uri (query, "http://example.com/gdata_test";);
-
 	g_assert_cmpstr (query_uri, ==, "http://example.com/gdata_test/-/A%7C-%7Burn%3Agoogle.com%7DB/-C?q=foobar";);
 	g_free (query_uri);
 
 	/* Same combination without q param */
 	gdata_query_set_q (query, NULL);
 	query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-
 	g_assert_cmpstr (query_uri, ==, "http://example.com/-/A%7C-%7Burn%3Agoogle.com%7DB/-C";);
 	g_free (query_uri);
 
@@ -235,6 +231,35 @@ test_query_categories (void)
 }
 
 static void
+test_query_unicode (void)
+{
+	GDataQuery *query;
+	gchar *query_uri;
+
+	g_test_bug ("602497");
+
+	/* Simple query */
+	query = gdata_query_new ("fööbar�");
+	query_uri = gdata_query_get_query_uri (query, "http://example.com";);
+	g_assert_cmpstr (query_uri, ==, "http://example.com?q=f%C3%B6%C3%B6bar%E2%80%BD";);
+	g_free (query_uri);
+
+	/* Categories */
+	gdata_query_set_categories (query, "�mlauts|¿Questions�");
+	query_uri = gdata_query_get_query_uri (query, "http://example.com";);
+	g_assert_cmpstr (query_uri, ==, "http://example.com/-/%C3%9Cmlauts%7C%C2%BFQuestions%E2%80%BD?q=f%C3%B6%C3%B6bar%E2%80%BD";);
+	g_free (query_uri);
+
+	/* Author */
+	gdata_query_set_author (query, "Lørd Brïan Ble�êd");
+	query_uri = gdata_query_get_query_uri (query, "http://example.com";);
+	g_assert_cmpstr (query_uri, ==, "http://example.com/-/%C3%9Cmlauts%7C%C2%BFQuestions%E2%80%BD?q=f%C3%B6%C3%B6bar%E2%80%BD&author=L%C3%B8rd%20Br%C3%AFan%20Ble%C3%9F%C3%AAd";);
+	g_free (query_uri);
+
+	g_object_unref (query);
+}
+
+static void
 test_color_parsing (void)
 {
 	GDataColor color;
@@ -1537,6 +1562,7 @@ main (int argc, char *argv[])
 	g_test_add_func ("/entry/get_xml", test_entry_get_xml);
 	g_test_add_func ("/entry/parse_xml", test_entry_parse_xml);
 	g_test_add_func ("/query/categories", test_query_categories);
+	g_test_add_func ("/query/unicode", test_query_unicode);
 	g_test_add_func ("/color/parsing", test_color_parsing);
 	g_test_add_func ("/color/output", test_color_output);
 



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