Commons Validator
  1. Commons Validator
  2. VALIDATOR-276

isValidURL call returns false for file scheme/protocol when URL is correct

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.3.1 Release
    • Fix Version/s: 1.4.0 Release
    • Component/s: Framework
    • Labels:
      None
    • Environment:

      Linux prometheus 2.6.26-1-amd64 #1 SMP Fri Mar 13 17:46:45 UTC 2009 x86_64 GNU/Linux, Debian sid

      Description

      Validate a URL using the file scheme/protocol for a file on a local Linux filesystem returns false. An extensive set of tests can be found here: URLTest.java.

      The following code snippet is a quick proof-of-concept:

      import org.apache.commons.validator.UrlValidator;
      
      class URLTest {
      
      	public static void main(String[] args) {
      		String url = "file:///etc/hosts";
      		UrlValidator urlValidator = new UrlValidator(new String[] {"http", "https", "ftp", "gopher", "file"});
      		boolean result = urlValidator.isValid(url);
      		System.out.println(String.format("URL '%s' is valid: %s", url, result));
      	}
      
      }
      

      This issue occurs whether the scheme String[] constructor or the ALLOW_ALL_SCHEMES equivalent is used.

        Activity

        Hide
        atc added a comment -

        JDK version: 1.6.0_14

        Show
        atc added a comment - JDK version: 1.6.0_14
        Hide
        atc added a comment - - edited

        This small app (URLTest.java) runs numerous tests, all of which should yield true but don't. I ran these with the following JARs:
        commons-validator-1.3.1.jar
        jakarta-oro-2.0.8.jar

        Show
        atc added a comment - - edited This small app ( URLTest.java ) runs numerous tests, all of which should yield true but don't. I ran these with the following JARs: commons-validator-1.3.1.jar jakarta-oro-2.0.8.jar
        Hide
        Jacob Zwiers added a comment -

        Even creating the UrlValidator as new UrlValidator( new String[]

        {"file"}

        , UrlValidator.ALLOW_2_SLASHES) does not allow URI using the file scheme to be validated property.

        Generally, the above test cases fail on the Authority.

        The validator requires an Authority (which it considers the start of the path name in at least some of the cases, empty in others) whereas RFC-2396 states that it's optional for some schemes (of which "file" would be one).

        Show
        Jacob Zwiers added a comment - Even creating the UrlValidator as new UrlValidator( new String[] {"file"} , UrlValidator.ALLOW_2_SLASHES) does not allow URI using the file scheme to be validated property. Generally, the above test cases fail on the Authority. The validator requires an Authority (which it considers the start of the path name in at least some of the cases, empty in others) whereas RFC-2396 states that it's optional for some schemes (of which "file" would be one).
        Hide
        Nick Burch added a comment -

        Should be fixed in r1128446.

        If you create your validator as:
        validator = new UrlValidator(new String[]

        {"http","file"}

        , UrlValidator.ALLOW_LOCAL_URLS);

        You can then correctly validate things like file:///etc/hosts and file:///c:/windows/hosts

        Show
        Nick Burch added a comment - Should be fixed in r1128446. If you create your validator as: validator = new UrlValidator(new String[] {"http","file"} , UrlValidator.ALLOW_LOCAL_URLS); You can then correctly validate things like file:///etc/hosts and file:///c:/windows/hosts

          People

          • Assignee:
            Unassigned
            Reporter:
            atc
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development