[Xfce4-commits] <midori:master> Tweak is_ip_address and add IPv6 test cases
Christian Dywan
noreply at xfce.org
Thu Mar 1 20:20:03 CET 2012
Updating branch refs/heads/master
to 7361a80e24bf6e37ad6646237aae9b487bbed62b (commit)
from 7e61fce9caa0a81782dc9b3f8f2bc089da34c034 (commit)
commit 7361a80e24bf6e37ad6646237aae9b487bbed62b
Author: Christian Dywan <christian at twotoasts.de>
Date: Wed Feb 29 23:17:02 2012 +0100
Tweak is_ip_address and add IPv6 test cases
Stop wrongly mistaking foo::bar for IPv6.
katze/midori-uri.vala | 13 +++++++++++--
midori/sokoke.c | 2 +-
tests/magic-uri.c | 16 +++++++++++++++-
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala
index 6a3c4c8..4dad32c 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 8cd7df7..4b34c94 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 46dbdda..f06a8b3 100644
--- a/tests/magic-uri.c
+++ b/tests/magic-uri.c
@@ -13,6 +13,7 @@
#include <midori/midori.h>
#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 at bar.baz", "http://f1o2o3:foo@bar.baz"); */
/* test_input ("foo:foo at 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";
More information about the Xfce4-commits
mailing list