From: Christian Dywan Date: Wed, 29 Feb 2012 22:17:02 +0000 (+0100) Subject: Tweak is_ip_address and add IPv6 test cases X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7361a80e24bf6e37ad6646237aae9b487bbed62b;p=midori Tweak is_ip_address and add IPv6 test cases Stop wrongly mistaking foo::bar for IPv6. --- diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala index 6a3c4c82..4dad32c1 100644 --- a/katze/midori-uri.vala +++ b/katze/midori-uri.vala @@ -125,8 +125,17 @@ namespace Midori { FIXME: Schemes are not handled hostname_is_ip_address () is not used because we'd have to separate the path from the URI first. */ - return uri != null && uri[0].isdigit () - && (uri.chr (4, '.') != null || uri.chr (4, ':') != null); + if (uri == null) + return false; + /* IPv4 */ + if (uri[0].isdigit () && (uri.chr (4, '.') != null)) + return true; + /* IPv6 */ + if (uri[0].isalnum () && uri[1].isalnum () + && uri[2].isalnum () && uri[3].isalnum () && uri[4] == ':' + && (uri[5] == ':' || uri[5].isalnum ())) + return true; + return false; } public static bool is_valid (string? uri) { return uri != null diff --git a/midori/sokoke.c b/midori/sokoke.c index 8cd7df7d..4b34c944 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -684,7 +684,7 @@ sokoke_magic_uri (const gchar* uri) search = NULL; if (!strchr (uri, ' ') && ((search = strchr (uri, ':')) || (search = strchr (uri, '@'))) && - search[0] && !g_ascii_isalpha (search[1])) + search[0] && g_ascii_isdigit (search[1])) return g_strconcat ("http://", uri, NULL); if ((!strcmp (uri, "localhost") || strchr (uri, '/')) && sokoke_resolve_hostname (uri)) diff --git a/tests/magic-uri.c b/tests/magic-uri.c index 46dbddac..f06a8b32 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -13,6 +13,7 @@ #include #define SM "http://www.searchmash.com/search/" +#define HTTP_PREFIX "midori-unit-test-expected-http-prefix" static void test_input (const gchar* input, @@ -20,6 +21,7 @@ test_input (const gchar* input, { static KatzeArray* search_engines = NULL; gchar* uri; + gchar* real_expected = NULL; if (G_UNLIKELY (!search_engines)) { @@ -58,7 +60,12 @@ test_input (const gchar* input, uri = search_uri ? midori_uri_for_search (search_uri, keywords) : NULL; } - katze_assert_str_equal (input, uri, expected); + + if (!g_strcmp0 (expected, HTTP_PREFIX)) + real_expected = g_strconcat ("http://", input, NULL); + + katze_assert_str_equal (input, uri, real_expected ? real_expected : expected); + g_free (real_expected); g_free (uri); } @@ -93,6 +100,13 @@ magic_uri_uri (void) /* test_input ("foo:f1o2o3@bar.baz", "http://f1o2o3:foo@bar.baz"); */ /* test_input ("foo:foo@bar.baz", "http://foo:foo@bar.baz"); */ + test_input ("2001:0db8:85a3:0000:0000:8a2e:0370:7334", HTTP_PREFIX); + test_input ("fe80:0:0:0:202:b3ff:fe1e:8329", HTTP_PREFIX); + test_input ("fe80::202:b3ff:fe1e:8329", HTTP_PREFIX); + test_input ("fe80::76e5:bff:fe04:38e0/64", HTTP_PREFIX); + test_input ("content::browser", NULL); + test_input ("std::copy", NULL); + uri = "http://bugs.launchpad.net/midori"; g_assert_cmpstr ("bugs.launchpad.net", ==, midori_uri_parse_hostname (uri, NULL)); uri = "https://bugs.launchpad.net/midori";