]> spindle.queued.net Git - midori/commitdiff
Don't mixup tokens starting with the same letters
authorPaweł Forysiuk <tuxator@o2.pl>
Wed, 8 Aug 2012 23:00:46 +0000 (01:00 +0200)
committerChristian Dywan <christian@twotoasts.de>
Wed, 8 Aug 2012 23:02:56 +0000 (01:02 +0200)
katze/katze-array.c
tests/magic-uri.c

index 6d11b5aea80396150da79830cafcb39eb9a79d1f..602c16470b183f2c7be44b1f67022748b2c6473a 100644 (file)
@@ -404,8 +404,13 @@ katze_array_find_token (KatzeArray*  array,
     for (items = array->items; items; items = g_list_next (items))
     {
         const gchar* found_token = ((KatzeItem*)items->data)->token;
-        if (found_token != NULL && !strncmp (token, found_token, token_length))
-            return items->data;
+        if (found_token != NULL)
+        {
+            guint bigger_item = strlen (found_token) > token_length ? strlen (found_token) : token_length;
+
+            if (strncmp (token, found_token, bigger_item) == 0)
+                return items->data;
+        }
     }
     return NULL;
 }
index 35f5781c80162062a1c7f965dfd6544468e1b294..b80bf153374dd4e954a3c9c9d0583461359eee57 100644 (file)
@@ -38,6 +38,16 @@ test_input (const gchar* input,
                              "token", "se", NULL);
         katze_array_add_item (search_engines, item);
         g_object_unref (item);
+        item = g_object_new (KATZE_TYPE_ITEM,
+                             "uri", "ddg.gg",
+                             "token", "dd", NULL);
+        katze_array_add_item (search_engines, item);
+        g_object_unref (item);
+        item = g_object_new (KATZE_TYPE_ITEM,
+                             "uri", "google.com",
+                             "token", "d", NULL);
+        katze_array_add_item (search_engines, item);
+        g_object_unref (item);
     }
 
     uri = sokoke_magic_uri (input);
@@ -160,6 +170,8 @@ static void
 magic_uri_search (void)
 {
     test_input ("sm midori", SM "midori");
+    test_input ("d midori browser", "google.com" "midori%20browser");
+    test_input ("dd midori browser", "ddg.gg" "midori%20browser");
     test_input ("sm cats dogs", SM "cats%20dogs");
     test_input ("se cats dogs", SM "cats%20dogs");
     test_input ("dict midori", NULL);