Issue Details (XML | Word | Printable)

Key: VALIDATOR-202
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Henri Yandell
Reporter: Ben
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons Validator

URL Validator isValid method fails with java.lang.ArrayIndexOutOfBoundsException at org.apache.commons.validator.UrlValidator.isValidAuthority(UrlValidator.java:367)

Created: 03/Oct/06 11:07 PM   Updated: 12/Nov/07 07:25 PM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3.1 Release

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works 202-fix.patch 2006-10-04 07:54 PM Henri Yandell 0.9 kB
Text File Licensed for inclusion in ASF works 202-test.patch 2006-10-04 07:26 PM Henri Yandell 1 kB
Environment: JBOSS Running on Linux
Issue Links:
Reference
 

Resolution Date: 05/Oct/06 06:29 PM


 Description  « Hide
Validating the following URL will throw an ArrayIndexOutOfBoundsException exception

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

Code:

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") ;



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Ben added a comment - 03/Oct/06 11:11 PM
Using commons-validator-1.3.0.jar - Version 1.3.0 of commons validator

Henri Yandell added a comment - 04/Oct/06 07:26 PM
Unit test.

Henri Yandell added a comment - 04/Oct/06 07:54 PM
Problem is that in that method an array of fixed size 10 is created. The patch resolves this by making the size of the array be the number of '.'s in the hostIP + 1.

Seems hacky


Ben added a comment - 04/Oct/06 09:50 PM
How can I get your fix?

Also you can always use an ArrayList instead of fixed size array so it wont seem so hacky.


Ben added a comment - 04/Oct/06 09:53 PM
Please ignore the previous comment as to where I can get the fix. I did not see the attached patch file.

Henri Yandell added a comment - 05/Oct/06 06:23 PM
ArrayList seemed like a 'doh' moment, but digging into it it's a bit of a pain to code.
You can't use set as you have to use add the first time in an ArrayList; so the code would need a large change.

When I was looking at this class there were a number of bits that were jumping up and down saying "RECODE ME!",
so I'm going to apply the two patches above to get the bug fixed in the nightly build tonight and then I'll look into rewriting things a bit.
ArrayList would work fine if the code was changed from set(..) to add(..) semantics, but I also think the whole thing could be simplified.


Henri Yandell added a comment - 05/Oct/06 06:27 PM
See VALIDATOR-203 for Jira issue to RECODE ME.

Henri Yandell added a comment - 05/Oct/06 06:29 PM
svn ci -m "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. "

Sending src/share/org/apache/commons/validator/UrlValidator.java
Sending src/test/org/apache/commons/validator/UrlTest.java
Transmitting file data ..
Committed revision 453308.