You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (JIRA)" <ji...@apache.org> on 2016/05/02 18:52:12 UTC

[jira] [Resolved] (VALIDATOR-391) UrlValidator.isValid throws exception for FILEURLs

     [ https://issues.apache.org/jira/browse/VALIDATOR-391?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved VALIDATOR-391.
----------------------------
       Resolution: Fixed
    Fix Version/s: 1.5.2

Thanks for the report and patches.
Fixed with some minor changes as below:

URL: http://svn.apache.org/viewvc?rev=1742006&view=rev
Log:
VALIDATOR-391 UrlValidator.isValid throws exception for FILEURLs
    Fixed code so it handles URLs with no authority field

Modified:
    commons/proper/validator/trunk/src/changes/changes.xml
    commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java


URL: http://svn.apache.org/viewvc?rev=1742007&view=rev
Log:
Must also test return code

Modified:
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java


> UrlValidator.isValid throws exception for FILEURLs
> --------------------------------------------------
>
>                 Key: VALIDATOR-391
>                 URL: https://issues.apache.org/jira/browse/VALIDATOR-391
>             Project: Commons Validator
>          Issue Type: Bug
>          Components: Routines
>    Affects Versions: 1.5.0
>            Reporter: Mark E. Scott, Jr.
>              Labels: easyfix
>             Fix For: 1.5.2
>
>         Attachments: UrlValidator.java.patch, UrlValidatorTest.java.patch
>
>
> In UrlValidator.java from v1.5.0, there is the following section which generates a null pointer exception, rendering isValid unusable for FILE URLs.
> {code:title=org/apache/commons/validator/routines/UrlValidator.java}
> if ("file".equals(scheme)) {// Special case - file: allows an empty authority
>             if (!"".equals(authority)) {
>                 if (authority.contains(":")) { // but cannot allow trailing :
>                     return false;
>                 }
>             }
>             // drop through to continue validation
>         }
> {code}
> In the case of a file URL given in my example below, authority is null, and thusly doesn't equal a blank string, so it drops down and calls authority.contains, which generates a NullPointerException.
> {code:title=Example to generate exception}
> File localFile = new File("c:\\path\\to\\dir\\");
> URL localURL = localFile.toURI().toURL();
> String urlString = localURL.toString(); // "file:/C:/path/to/dir/"
> String[] schemes = {"file"};
> UrlValidator urlValidator = new UrlValidator(schemes);
> urlValidator.isValid(urlString); // null pointer exception
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)