Fixed default search engine lookup without handle.
authorDaniel Carl <danielcarl@gmx.de>
Fri, 29 Mar 2013 11:24:29 +0000 (12:24 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Fri, 29 Mar 2013 11:24:29 +0000 (12:24 +0100)
To get the search handle the string after :open was split by space char. If
only one term was given we skipped the lookup of the search engine so that it
wasn't possible to search for a single term without a given search handle.

src/main.c
src/searchengine.c

index 4b88bb7..2576190 100644 (file)
@@ -137,7 +137,6 @@ gboolean vb_eval_script(WebKitWebFrame* frame, char* script, char* file, char**
 gboolean vb_load_uri(const Arg* arg)
 {
     char* uri;
-    char* part;
     char* path = arg->s;
     struct stat st;
 
@@ -154,18 +153,27 @@ gboolean vb_load_uri(const Arg* arg)
     if (stat(path, &st) == 0) {
         char* rp = realpath(path, NULL);
         uri = g_strdup_printf("file://%s", rp);
-    } else if (!strchr(path, '.') && (part = strchr(path, ' '))) {
-        /* look up for a searchengine */
-        *part = '\0';
-        char* search_uri = searchengine_get_uri(path);
-        char* term       = soup_uri_encode(part + 1, "&");
-
-        if (search_uri) {
-            uri = g_strdup_printf(search_uri, term);
+    } else if (!strchr(path, '.')) {
+        char* part  = NULL;
+        char* tmpl  = NULL;
+        char* query = NULL;
+
+        /* look up for a searchengine with handle */
+        if ((part = strchr(path, ' '))) {
+            *part = '\0';
+            tmpl  = searchengine_get_uri(path);
+            query = soup_uri_encode(part + 1, "&");
+        } else {
+            tmpl  = searchengine_get_uri(NULL);
+            query = soup_uri_encode(path, "&");
+        }
+
+        if (tmpl) {
+            uri = g_strdup_printf(tmpl, query);
         } else {
             uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
         }
-        g_free(term);
+        g_free(query);
     } else {
         uri = g_strrstr(path, "://") ? g_strdup(path) : g_strdup_printf("http://%s", path);
     }
index 9eb07cb..cabbc76 100644 (file)
@@ -80,10 +80,10 @@ gboolean searchengine_set_default(const char* handle)
 
 char* searchengine_get_uri(const char* handle)
 {
-    char* def = vb.behave.searchengine_default;
-    GSList* l = searchengine_find(handle);
+    const char* def = vb.behave.searchengine_default;
+    GSList* l = NULL;
 
-    if (l) {
+    if (handle && (l = searchengine_find(handle))) {
         return ((Searchengine*)l->data)->uri;
     } else if (def && (l = searchengine_find(def))) {
         return ((Searchengine*)l->data)->uri;