summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it.class3
-rwxr-xr-xtest/it.t7
2 files changed, 9 insertions, 1 deletions
diff --git a/it.class b/it.class
index 539cf5a..5a765db 100644
--- a/it.class
+++ b/it.class
@@ -456,11 +456,12 @@ static function is_private_ip($host)
{
if ($ip !== filter_var($ip, FILTER_VALIDATE_IP))
continue;
+ $gotvalidip = true;
if ($ip !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
return true;
}
- return false;
+ return $gotvalidip ? false : true;
}
diff --git a/test/it.t b/test/it.t
index 69b46b6..19f445f 100755
--- a/test/it.t
+++ b/test/it.t
@@ -349,6 +349,13 @@ is(it::is_private_ip('cname.gna.ch'), true, "is_private_ip cn
is(it::is_private_ip('pub4.gna.ch'), true, "is_private_ip pub4.gna.ch has public ipv4 but private ipv6");
is(it::is_private_ip('pub6.gna.ch'), true, "is_private_ip pub6.gna.ch has private ipv6 and public ipv6");
+# Stuff which is interpreted by curl
+is(it::is_private_ip('127.1'), true, "is_private_ip loopback ipv4 (zeroes omitted)");
+is(it::is_private_ip('127.0.0.01'), true, "is_private_ip loopback ipv4 (octal)");
+is(it::is_private_ip('127.0.0.0x1'), true, "is_private_ip loopback ipv4 (hexadecimal)");
+is(it::is_private_ip('127.01.0x1'), true, "is_private_ip private with omissions, octal and hexadecimal");
+is(it::is_private_ip('128.01.0x1'), false, "TODO: is_private_ip non-private with omissions, octal and hexadecimal");
+
# it::filter_keys tests
$data = ['a' => 1, 'b' => 2, 'c' => 3];