You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2006/10/05 20:29:10 UTC

svn commit: r453308 - in /jakarta/commons/proper/validator/trunk/src: share/org/apache/commons/validator/UrlValidator.java test/org/apache/commons/validator/UrlTest.java

Author: bayard
Date: Thu Oct  5 11:29:09 2006
New Revision: 453308

URL: http://svn.apache.org/viewvc?view=rev&rev=453308
Log:
Fixing ArrayOutOfBoundsException bug reported in #VALIDATOR-202. This fix is pretty simple - 'Create an array of size # of .s plus one', but the implementation of that isn't very beautiful. 

Modified:
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/UrlValidator.java
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/UrlTest.java

Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/UrlValidator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/UrlValidator.java?view=diff&rev=453308&r1=453307&r2=453308
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/UrlValidator.java (original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/UrlValidator.java Thu Oct  5 11:29:09 2006
@@ -355,7 +355,16 @@
 
 //rightmost hostname will never start with a digit.
         if (hostname) {
-            String[] domainSegment = new String[10];
+            // LOW-TECH FIX FOR VALIDATOR-202
+            // TODO: Rewrite to use ArrayList and .add semantics: see VALIDATOR-203
+            char[] chars = hostIP.toCharArray();
+            int size = 1;
+            for(int i=0; i<chars.length; i++) {
+                if(chars[i] == '.') {
+                    size++;
+                }
+            }
+            String[] domainSegment = new String[size];
             boolean match = true;
             int segmentCount = 0;
             int segmentLength = 0;

Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/UrlTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/UrlTest.java?view=diff&rev=453308&r1=453307&r2=453308
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/UrlTest.java (original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/UrlTest.java Thu Oct  5 11:29:09 2006
@@ -135,6 +135,12 @@
       }
    }
 
+   public void testValidator202() {
+       String[] schemes = {"http","https"};
+       UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS);
+       urlValidator.isValid("http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log");
+   }
+
    static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) {
       boolean carry = true;  //add 1 to lowest order part.
       boolean maxIndex = true;
@@ -278,4 +284,4 @@
                             new TestPair("telnet", false)};
 
 
-}
\ No newline at end of file
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org