Uploaded image for project: 'Commons Validator'
  1. Commons Validator
  2. VALIDATOR-334

UrlValidator: isValidAuthority() returning true when supplied authority validator fails

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.0 Release
    • Fix Version/s: 1.4.1 Release
    • Component/s: Routines
    • Labels:
      None

      Description

      When UrlValidator is supplied an authority validator, if the authority fails the authority validator, but is an otherwise valid authority, the UrlValidator reports the URL is valid. Here is a test case:

          @Test
          public void testUrlValidator() throws Exception {
              String regex = ".*amazon\\.com";
              RegexValidator authorityValidator = new RegexValidator(regex);
              UrlValidator validator = new UrlValidator(authorityValidator, UrlValidator.ALLOW_ALL_SCHEMES);
      
              assertThat("amazon.com", Pattern.matches(regex, "amazon.com"), is(true));
              assertThat("google.com", Pattern.matches(regex, "google.com"), is(false));
      
              assertThat("amazon.com", authorityValidator.isValid("amazon.com"), is(true));
              assertThat("google.com", authorityValidator.isValid("google.com"), is(false));
      
              assertThat("amazon.com", validator.isValid("http://amazon.com/somepath"), is(true));
              assertThat("google.com", validator.isValid("http://google.com/somepath"), is(false));   // fails
          }
      

      It appears that UrlAuthority.isValidAuthority() will return true if the URL passes the authorityValidator (line 365). But if the URL fails the authorityValidator, it can still pass the other validation checks. Shouldn't the validation fail if the URL fails the authorityValidator, regardless if it is an otherwise valid authority?

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                fransonsr Scott Franson
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: