HTTPCLIENT-1631: IPv4 addresses parser accepts addresses that starts with zero

Contributed by Maxim Kirilov <kir.maxim at gmail.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1665995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2015-03-11 20:28:36 +00:00
parent a319a25f4e
commit 2220d106c1
2 changed files with 3 additions and 1 deletions

View File

@ -43,7 +43,8 @@ public class InetAddressUtils {
}
private static final String IPV4_BASIC_PATTERN_STRING =
"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}" + // initial 3 fields, 0-255 followed by .
"(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){1}" + // initial first field, 1-255
"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){2}" + // following 2 fields, 0-255 followed by .
"([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"; // final field, 0-255
private static final Pattern IPV4_PATTERN =

View File

@ -48,6 +48,7 @@ public class TestInetAddressUtils {
Assert.assertFalse(InetAddressUtils.isIPv4Address("g.ar.ba.ge"));
Assert.assertFalse(InetAddressUtils.isIPv4Address("192.168.0"));
Assert.assertFalse(InetAddressUtils.isIPv4Address("256.255.255.255"));
Assert.assertFalse(InetAddressUtils.isIPv4Address("0.168.0.0")); //IP address that starts with zero not allowed
}
@Test