From 58d1436d4e37787c0d7107e8f542b9f061b39086 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 29 Aug 2012 20:28:46 +0200 Subject: [PATCH] Check that valid IP address has no leading 0 --- katze/midori-uri.vala | 2 +- tests/magic-uri.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala index 5a8fab3e..21681cb0 100644 --- a/katze/midori-uri.vala +++ b/katze/midori-uri.vala @@ -131,7 +131,7 @@ namespace Midori { if (uri.chr (-1, '@') != null) return is_ip_address (uri.split ("@")[1]); /* IPv4 */ - if (uri[0].isdigit () && (uri.chr (4, '.') != null)) + if (uri[0] != '0' && uri[0].isdigit () && (uri.chr (4, '.') != null)) return true; /* IPv6 */ if (uri[0].isalnum () && uri[1].isalnum () diff --git a/tests/magic-uri.c b/tests/magic-uri.c index 826307fd..d90e2b3f 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -258,6 +258,7 @@ magic_uri_ip (void) { g_assert (midori_uri_is_ip_address ("192.168.1.1")); g_assert (midori_uri_is_ip_address ("192.168.1.1:1234")); + g_assert (!midori_uri_is_ip_address ("0.168.1.1")); g_assert (midori_uri_is_ip_address ("user@192.168.1.1")); g_assert (midori_uri_is_ip_address ("user:password@192.168.1.1")); g_assert (midori_uri_is_ip_address ("2001:0db8:85a3:0000:0000:8a2e:0370:7334")); -- 2.39.5