Check that valid IP address has no leading 0

This commit is contained in:
Christian Dywan 2012-08-29 20:28:46 +02:00
parent 1c1fd1740e
commit 58d1436d4e
2 changed files with 2 additions and 1 deletions

View file

@ -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 ()

View file

@ -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"));