You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/03/11 21:28:37 UTC

svn commit: r1665995 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/conn/util/InetAddressUtils.java test/java/org/apache/http/conn/util/TestInetAddressUtils.java

Author: olegk
Date: Wed Mar 11 20:28:36 2015
New Revision: 1665995

URL: http://svn.apache.org/r1665995
Log:
HTTPCLIENT-1631: IPv4 addresses parser accepts addresses that starts with zero
Contributed by Maxim Kirilov <kir.maxim at gmail.com>

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/InetAddressUtils.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/util/TestInetAddressUtils.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/InetAddressUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/InetAddressUtils.java?rev=1665995&r1=1665994&r2=1665995&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/InetAddressUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/util/InetAddressUtils.java Wed Mar 11 20:28:36 2015
@@ -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 =

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/util/TestInetAddressUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/util/TestInetAddressUtils.java?rev=1665995&r1=1665994&r2=1665995&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/util/TestInetAddressUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/util/TestInetAddressUtils.java Wed Mar 11 20:28:36 2015
@@ -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