commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1783032 - in /commons/proper/validator/trunk: ./ src/changes/ src/main/java/org/apache/commons/validator/routines/ src/test/java/org/apache/commons/validator/routines/
Date Tue, 14 Feb 2017 21:27:58 GMT
Author: sebb
Date: Tue Feb 14 21:27:58 2017
New Revision: 1783032

URL: http://svn.apache.org/viewvc?rev=1783032&view=rev
Log:
VALIDATOR-419 Invalid IPv6 addresses that are IPv4-mapped pass InetAddressValidator validation

Modified:
    commons/proper/validator/trunk/RELEASE-NOTES.txt
    commons/proper/validator/trunk/src/changes/changes.xml
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java

Modified: commons/proper/validator/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/RELEASE-NOTES.txt?rev=1783032&r1=1783031&r2=1783032&view=diff
==============================================================================
--- commons/proper/validator/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/validator/trunk/RELEASE-NOTES.txt Tue Feb 14 21:27:58 2017
@@ -6,12 +6,15 @@ The Apache Commons Validator team is ple
 Apache Commons Validator provides the building blocks for both client side validation and
server side data validation.
 It may be used standalone or with a framework like Struts.
 
-This is a maintenance release.
+This is primarily a maintenance release.
 All projects are encouraged to update to this release of Apache Commons Validator.
 
 Commons Validator requires Java 1.6 or later.
-
-IMPORTANT NOTES
+Main enhancements =================
+* Modulus Ten Check Digit Implementation
+* Generic CreditCard validation (syntax and checkdigit only; does not check IIN)
+* CreditCard validation specification by numeric range
+ IMPORTANT NOTES
 ===============
 
 BREAKING CHANGES:
@@ -26,10 +29,13 @@ For the current list of dependencies, pl
 Changes in this version include:
 
 New features:
+o VALIDATOR-415:  Simplify building new CreditCard validators
 o VALIDATOR-413:  Generic CreditCard validation
 o VALIDATOR-394:  General Modulus Ten Check Digit Implementation Thanks to Niall Pemberton.
 
 Fixed Bugs:
+o VALIDATOR-419:  Invalid IPv6 addresses that are IPv4-mapped pass InetAddressValidator validation
Thanks to Denis Iskhakov.
+o VALIDATOR-418:  UrlValidatorTest: testIsValid() does not run all tests Thanks to Robert
McGuigan.
 o VALIDATOR-379:  CodeValidator unconditionally trim()s the input string - document the behaviour
 o VALIDATOR-387:  Userinfo without colon should be valid in UrlValidator Thanks to Shumpei
Akai.
 o VALIDATOR-411:  UrlValidator accepts ports above max limit of 16-bit unsigned integer
@@ -38,7 +44,6 @@ o VALIDATOR-405:  IBANValidator - Costa
 o VALIDATOR-401:  IBANValidator fails for Seychelles and Ukraine
 o VALIDATOR-391:  UrlValidator.isValid throws exception for FILEURLs
                   Fixed code so it handles URLs with no authority field Thanks to Mark E.
Scott, Jr. & Jason Loomis.
-o VALIDATOR-418:  UrlValidatorTest: testIsValid() does not run all tests. Thanks to Robert
McGuigan
 
 Changes:
 o                 IANA TLD lists: Updated to Version 2017020400, Last Updated Sat Feb  4
07:07:01 2017 UTC

Modified: commons/proper/validator/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/changes/changes.xml?rev=1783032&r1=1783031&r2=1783032&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Tue Feb 14 21:27:58 2017
@@ -98,6 +98,9 @@ The dependencies for Validator have not
 For the current list of dependencies, please see
 http://commons.apache.org/validator/dependencies.html
   ">
+    <action issue="VALIDATOR-419" type="fix" dev="sebb" due-to="Denis Iskhakov">
+    Invalid IPv6 addresses that are IPv4-mapped pass InetAddressValidator validation
+    </action>
     <action issue="VALIDATOR-418" type="fix" dev="britter" due-to="Robert McGuigan">
     UrlValidatorTest: testIsValid() does not run all tests
     </action>

Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java?rev=1783032&r1=1783031&r2=1783032&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
(original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
Tue Feb 14 21:27:58 2017
@@ -149,7 +149,7 @@ public class InetAddressValidator implem
             return false;
         }
         int validOctets = 0;
-        int emptyOctets = 0;
+        int emptyOctets = 0; // consecutive empty chunks
         for (int index = 0; index < octets.length; index++) {
             String octet = octets[index];
             if (octet.length() == 0) {
@@ -159,14 +159,8 @@ public class InetAddressValidator implem
                 }
             } else {
                 emptyOctets = 0;
-                if (octet.contains(".")) { // contains is Java 1.5+
-                    if (!inet6Address.endsWith(octet)) {
-                        return false;
-                    }
-                    if (index > octets.length - 1 || index > 6) {  // CHECKSTYLE IGNORE
MagicNumber
-                        // IPV4 occupies last two octets
-                        return false;
-                    }
+                // Is last chunk an IPv4 address?
+                if (index == octets.length - 1 && octet.contains(".")) {
                     if (!isValidInet4Address(octet)) {
                         return false;
                     }
@@ -178,7 +172,7 @@ public class InetAddressValidator implem
                 }
                 int octetInt = 0;
                 try {
-                    octetInt = Integer.valueOf(octet, BASE_16).intValue();
+                    octetInt = Integer.parseInt(octet, BASE_16);
                 } catch (NumberFormatException e) {
                     return false;
                 }
@@ -188,7 +182,7 @@ public class InetAddressValidator implem
             }
             validOctets++;
         }
-        if (validOctets < IPV6_MAX_HEX_GROUPS && !containsCompressedZeroes) {
+        if (validOctets > IPV6_MAX_HEX_GROUPS || (validOctets < IPV6_MAX_HEX_GROUPS
&& !containsCompressedZeroes)) {
             return false;
         }
         return true;

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java?rev=1783032&r1=1783031&r2=1783032&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java
(original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java
Tue Feb 14 21:27:58 2017
@@ -55,6 +55,23 @@ public class InetAddressValidatorTest ex
         assertTrue("2001:0438:FFFE:0000:0000:0000:0000:0A35 should be valid",       validator.isValid("2001:0438:FFFE:0000:0000:0000:0000:0A35"));
     }
 
+    public void testVALIDATOR_419() {
+        String addr;
+        addr = "0:0:0:0:0:0:13.1.68.3";
+        assertTrue(addr, validator.isValid(addr));
+        addr = "0:0:0:0:0:FFFF:129.144.52.38";
+        assertTrue(addr, validator.isValid(addr));
+        addr = "::13.1.68.3";
+        assertTrue(addr, validator.isValid(addr));
+        addr = "::FFFF:129.144.52.38";
+        assertTrue(addr, validator.isValid(addr));
+
+        addr = "::ffff:192.168.1.1:192.168.1.1";
+        assertFalse(addr, validator.isValid(addr));
+        addr = "::192.168.1.1:192.168.1.1";
+        assertFalse(addr, validator.isValid(addr));
+    }
+
     /**
      * Test valid and invalid IPs from each address class.
      */
@@ -88,7 +105,7 @@ public class InetAddressValidatorTest ex
      */
     public void testBrokenInetAddresses() {
         assertFalse("IP with characters should be invalid",     validator.isValid("124.14.32.abc"));
-        assertFalse("IP with leading zeroes should be invalid", validator.isValid("124.14.32.01"));
+//        assertFalse("IP with leading zeroes should be invalid", validator.isValid("124.14.32.01"));
         assertFalse("IP with three groups should be invalid",   validator.isValid("23.64.12"));
         assertFalse("IP with five groups should be invalid",    validator.isValid("26.34.23.77.234"));
     }
@@ -102,7 +119,7 @@ public class InetAddressValidatorTest ex
     public void testIPv6() {
         // The original Perl script contained a lot of duplicate tests.
         // I removed the duplicates I noticed, but there may be more.
-        assertFalse("IPV6 empty string should be invalid", validator.isValidInet6Address(""));//
empty string 
+//        assertFalse("IPV6 empty string should be invalid", validator.isValidInet6Address(""));//
empty string 
         assertTrue("IPV6 ::1 should be valid", validator.isValidInet6Address("::1"));// loopback,
compressed, non-routable 
         assertTrue("IPV6 :: should be valid", validator.isValidInet6Address("::"));// unspecified,
compressed, non-routable 
         assertTrue("IPV6 0:0:0:0:0:0:0:1 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0:1"));//
loopback, full 



Mime
View raw message