From: Paweł Forysiuk Date: Wed, 8 Aug 2012 23:00:46 +0000 (+0200) Subject: Don't mixup tokens starting with the same letters X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5da45a40ef01eccce9ed249eca37ab69f8fc829;p=midori Don't mixup tokens starting with the same letters --- diff --git a/katze/katze-array.c b/katze/katze-array.c index 6d11b5ae..602c1647 100644 --- a/katze/katze-array.c +++ b/katze/katze-array.c @@ -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; } diff --git a/tests/magic-uri.c b/tests/magic-uri.c index 35f5781c..b80bf153 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -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);