Append the search term if a search lacks a '%s'

This commit is contained in:
Christian Dywan 2009-01-02 23:15:01 +01:00
parent 813a29de94
commit ac146cbd78
2 changed files with 13 additions and 1 deletions

View file

@ -187,7 +187,12 @@ sokoke_magic_uri (const gchar* uri,
} }
g_free (parts); g_free (parts);
if (search_uri) if (search_uri)
{
if (strstr (search_uri, "%s"))
search = g_strdup_printf (search_uri, parts[1]); search = g_strdup_printf (search_uri, parts[1]);
else
search = g_strdup_printf ("%s%s", search_uri, parts[1]);
}
return search; return search;
} }
return g_strdup (uri); return g_strdup (uri);

View file

@ -32,6 +32,12 @@ main (int argc,
"uri", "http://www.searchmash.com/search/%s", "uri", "http://www.searchmash.com/search/%s",
"token", "sm", NULL); "token", "sm", NULL);
katze_array_add_item (search_engines, item); katze_array_add_item (search_engines, item);
g_object_unref (item);
item = g_object_new (KATZE_TYPE_ITEM,
"uri", "http://www.searchmash.com/search/",
"token", "se", NULL);
katze_array_add_item (search_engines, item);
g_object_unref (item);
#define test_input(input, expected) \ #define test_input(input, expected) \
uri = sokoke_magic_uri (input, search_engines); \ uri = sokoke_magic_uri (input, search_engines); \
@ -65,6 +71,7 @@ main (int argc,
test_input ("192.168.1.1:8000", "http://192.168.1.1:8000"); test_input ("192.168.1.1:8000", "http://192.168.1.1:8000");
test_input ("sm midori", SM "midori"); test_input ("sm midori", SM "midori");
test_input ("sm cats dogs", SM "cats dogs"); test_input ("sm cats dogs", SM "cats dogs");
test_input ("se cats dogs", SM "cats dogs");
test_input ("dict midori", NULL); test_input ("dict midori", NULL);
test_input ("cats", NULL); test_input ("cats", NULL);
test_input ("cats dogs", NULL); test_input ("cats dogs", NULL);