[gnome-software/wip/ubuntu-xenial] snapd: Correctly escape search terms



commit 66cac113d3e7d8fb5b45d1ba6b87c03f588edf1e
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Jul 4 16:01:34 2016 +1200

    snapd: Correctly escape search terms

 src/plugins/gs-plugin-snap.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/gs-plugin-snap.c b/src/plugins/gs-plugin-snap.c
index 16b871a..7a296ca 100644
--- a/src/plugins/gs-plugin-snap.c
+++ b/src/plugins/gs-plugin-snap.c
@@ -210,16 +210,28 @@ get_apps (GsPlugin *plugin,
        JsonObject *root;
        JsonArray *result;
        GList *snaps;
-       GList *i;
+       GList *l;
 
        /* Get all the apps */
        query_fields = g_ptr_array_new_with_free_func (g_free);
-       if (sources != NULL)
-               g_ptr_array_add (query_fields, g_strdup_printf ("sources=%s", sources));
-       if (search_terms != NULL) {
-               g_autofree gchar *query = NULL;
-               query = g_strjoinv ("+", search_terms);
-               g_ptr_array_add (query_fields, g_strdup_printf ("q=%s", query));
+       if (sources != NULL) {
+               g_autofree gchar *escaped;
+               escaped = soup_uri_encode (sources, NULL);
+               g_ptr_array_add (query_fields, g_strdup_printf ("sources=%s", escaped));
+       }
+       if (search_terms != NULL && search_terms[0] != NULL) {
+               g_autoptr (GString) query = NULL;
+               g_autofree gchar *escaped = NULL;
+               gint i;
+
+               query = g_string_new ("q=");
+               escaped = soup_uri_encode (search_terms[0], NULL);
+               g_string_append (query, escaped);
+               for (i = 1; search_terms[i] != NULL; i++) {
+                       g_autofree gchar *e = soup_uri_encode (search_terms[0], NULL);
+                       g_string_append_printf (query, "+%s", e);
+               }
+               g_ptr_array_add (query_fields, g_strdup (query->str));
                path = g_string_new ("/v2/find");
        }
        else
@@ -256,8 +268,8 @@ get_apps (GsPlugin *plugin,
        result = json_object_get_array_member (root, "result");
        snaps = json_array_get_elements (result);
 
-       for (i = snaps; i != NULL; i = i->next) {
-               JsonObject *package = json_node_get_object (i->data);
+       for (l = snaps; l != NULL; l = l->next) {
+               JsonObject *package = json_node_get_object (l->data);
                g_autoptr(GsApp) app = NULL;
                const gchar *id;
 


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