[epiphany/wip/lantw/search-engine-manager-escape-the-search-string] search-engine-manager: escape the search string



commit 036310b167e0f2c11d4355e73f5e380dce7c7f7a
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Wed Sep 25 21:19:15 2019 +0800

    search-engine-manager: escape the search string
    
    When a user types a search string with special characters, they should
    be escaped before they are used as a part of a URL. For example, if a
    user types "!g c++", it should mean searching Google for "c++", not
    searching for "c  " just because "+" means " " in a URL.

 lib/ephy-search-engine-manager.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/lib/ephy-search-engine-manager.c b/lib/ephy-search-engine-manager.c
index ef4ffe2ef..984ad1f89 100644
--- a/lib/ephy-search-engine-manager.c
+++ b/lib/ephy-search-engine-manager.c
@@ -27,6 +27,8 @@
 #include "ephy-settings.h"
 #include "ephy-prefs.h"
 
+#include <libsoup/soup.h>
+
 #define FALLBACK_ADDRESS "https://duckduckgo.com/?q=%s&t=epiphany";
 
 enum {
@@ -314,20 +316,25 @@ ephy_search_engine_manager_replace_pattern (const char *string,
                                             const char *replace)
 {
   gchar **strings;
+  gchar *query_param;
+  const gchar *escaped_replace;
   GString *buffer;
 
   strings = g_strsplit (string, pattern, -1);
+  query_param = soup_form_encode ("q", replace, NULL);
+  escaped_replace = query_param + 2;
 
   buffer = g_string_new (NULL);
 
   for (guint i = 0; strings[i] != NULL; i++) {
     if (i > 0)
-      g_string_append (buffer, replace);
+      g_string_append (buffer, escaped_replace);
 
     g_string_append (buffer, strings[i]);
   }
 
   g_strfreev (strings);
+  g_free (query_param);
 
   return g_string_free (buffer, FALSE);
 }


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