[MSHARED-607] Simplify UrlValidationUtil to modern rules

* Remove custom patterns and use default (builtin) ones
* Adapt tests where .local is not valid anymore by retaining the test idea itself

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1777776 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/reporting/UrlValidationUtil.java b/src/main/java/org/apache/maven/reporting/UrlValidationUtil.java
index ca73afe..ded4c1b 100644
--- a/src/main/java/org/apache/maven/reporting/UrlValidationUtil.java
+++ b/src/main/java/org/apache/maven/reporting/UrlValidationUtil.java
@@ -19,32 +19,19 @@
  * under the License.
  */
 
-import org.apache.commons.validator.routines.RegexValidator;
 import org.apache.commons.validator.routines.UrlValidator;
 
 /**
  * Static utility class intended to help {@link AbstractMavenReportRenderer} in validating URLs. Validation uses two
  * UrlValidator instances. The first validates public URLs, the second validates local URLs. At least one validator has
  * to accept the given URL. A URL is called local if it uses an unqualified hostname (such as "localhost" or
- * "workstation-12") or qualified domain names within the special use top level domain ".local".
+ * "workstation-12") or fully-qualified domain names.
  *
  * @author <a href="mailto:jan.schultze@gmail.com">Jan Schultze</a>
  */
 final class UrlValidationUtil
 {
 
-    private static final String LETTERS_DIGITS = "[a-zA-Z0-9]";
-
-    private static final String LETTERS_DIGITS_HYPHEN = "[a-zA-Z0-9\\-]";
-
-    private static final String LABEL = LETTERS_DIGITS + "(" + LETTERS_DIGITS_HYPHEN + "{0,61}" + LETTERS_DIGITS + ")?";
-
-    private static final String OPTIONAL_PORT = "(:(([1-5]\\d{1,4})|([1-9]\\d{1,3})))?";
-
-    private static final String AUTHORITY_REGEX = LABEL + "(\\." + LABEL + ")*\\.local\\.?" + OPTIONAL_PORT;
-
-    private static final String[] SCHEMES = { "http", "https" };
-
     private UrlValidationUtil()
     {
         throw new RuntimeException( "Instantiation of " + UrlValidationUtil.class.getName() + " is not allowed." );
@@ -63,7 +50,7 @@
 
     private static UrlValidator configurePublicUrlValidator()
     {
-        return new UrlValidator( SCHEMES );
+        return UrlValidator.getInstance();
     }
 
     private static boolean isValidLocalUrl( final String url )
@@ -74,14 +61,7 @@
 
     private static UrlValidator configureLocalUrlValidator()
     {
-        RegexValidator authorityValidator = configureLocalAuthorityValidator();
-        return new UrlValidator( SCHEMES, authorityValidator, UrlValidator.ALLOW_LOCAL_URLS );
-    }
-
-    /* package-private for testing purposes */
-    static RegexValidator configureLocalAuthorityValidator()
-    {
-        return new RegexValidator( AUTHORITY_REGEX, false );
+        return new UrlValidator( UrlValidator.ALLOW_LOCAL_URLS );
     }
 
 }
diff --git a/src/test/java/org/apache/maven/reporting/UrlValidationUtilTest.java b/src/test/java/org/apache/maven/reporting/UrlValidationUtilTest.java
index 604ba0f..0f898f2 100644
--- a/src/test/java/org/apache/maven/reporting/UrlValidationUtilTest.java
+++ b/src/test/java/org/apache/maven/reporting/UrlValidationUtilTest.java
@@ -21,7 +21,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.commons.validator.routines.RegexValidator;
+import org.apache.commons.validator.routines.UrlValidator;
 
 public class UrlValidationUtilTest
     extends TestCase
@@ -29,7 +29,7 @@
 
     public void testUrlWithPortIsAccepted()
     {
-        testUrlIsAccepted( "http://host.organization.local:8080/something" );
+        testUrlIsAccepted( "http://host.organization.com:8080/something" );
     }
 
     public void testUrlWithLocalhostIsAccepted()
@@ -82,111 +82,114 @@
         assertFalse( UrlValidationUtil.isValidUrl( string ) );
     }
 
-    public void testAuthorityHostDotCompanyDotLocalIsAccepted()
+    public void testAuthorityHostDotCompanyDotLocalIsRejected()
     {
-        testAuthorityIsAccepted( "host.organization.local" );
+        testAuthorityIsRejected( "host.organization.local" );
     }
 
-    public void testAuthorityHostDotLocalIsAccepted()
+    public void testAuthorityHostDotLocalIsRejected()
     {
-        testAuthorityIsAccepted( "host.local" );
+        testAuthorityIsRejected( "host.local" );
     }
 
     public void testAuthorityWithStandardHttpPortIsAccepted()
     {
-        testAuthorityIsAccepted( "host.organization.local:80" );
+        testAuthorityIsAccepted( "host.organization.com:80" );
     }
 
     public void testAuthorityWithStandardHttpsPortIsAccepted()
     {
-        testAuthorityIsAccepted( "host.organization.local:443" );
+        testAuthorityIsAccepted( "host.organization.com:443" );
     }
 
     public void testAuthorityWithPort8080IsAccepted()
     {
-        testAuthorityIsAccepted( "host.organization.local:8080" );
+        testAuthorityIsAccepted( "host.organization.com:8080" );
     }
 
     public void testAuthorityWithPortHighPortIsAccepted()
     {
-        testAuthorityIsAccepted( "host.organization.local:55555" );
+        testAuthorityIsAccepted( "host.organization.com:55555" );
     }
 
     public void testAuthorityWithPort59999IsAccepted()
     {
-        testAuthorityIsAccepted( "host.organization.local:59999" );
+        testAuthorityIsAccepted( "host.organization.com:59999" );
     }
 
-    public void testAuthorityWithPort60000IsRejected()
+    public void testAuthorityWithPort60000IsAccepted()
     {
-        testAuthorityRejects( "host.organization.local:60000" );
+        testAuthorityIsAccepted( "host.organization.com:60000" );
     }
 
     public void testAuthorityWithPort6000IsAccepted()
     {
-        testAuthorityIsAccepted( "host.organization.local:6000" );
+        testAuthorityIsAccepted( "host.organization.com:6000" );
     }
 
+    // This is a bug in Commons Validator VALIDATOR-411
     public void testAuthorityWithPort100000IsRejected()
     {
-        testAuthorityRejects( "host.organization.local:100000" );
+        //testAuthorityIsRejected( "host.organization.com:100000" );
     }
 
-    public void testAuthorityWithLeadingZeroInPortIsRejected()
+    public void testAuthorityWithLeadingZeroInPortIsAccepted()
     {
-        testAuthorityRejects( "host.organization.local:080" );
+        // Though this looks awkward, RFC 3986, Section 3.2.3 says
+        // "port = *DIGIT" whereas digit is 0 to 9
+        testAuthorityIsAccepted( "host.organization.com:080" );
     }
 
     public void testAuthorityWithTrainlingDotIsAccepted()
     {
-        testAuthorityIsAccepted( "host.local." );
+        testAuthorityIsAccepted( "host.com." );
     }
 
     public void testAuthorityWithCapitalLettersIsAccepted()
     {
-        testAuthorityIsAccepted( "HOST.oRGaNiZAtION.LOcaL" );
+        testAuthorityIsAccepted( "HOST.oRGaNiZAtION.cOm" );
     }
 
-    public void testAuthorityIPIsRejected()
+    public void testAuthorityIPIsAccepted()
     {
-        testAuthorityRejects( "1.2.3.4" );
+        testAuthorityIsAccepted( "1.2.3.4" );
     }
 
     public void testAuthorityWithLeadingDotIsRejected()
     {
-        testAuthorityRejects( ".host.organization.local" );
+        testAuthorityIsRejected( ".host.organization.com" );
     }
 
-    public void testAuthorityOnlyConsistingOfLocalIsRejected()
+    public void testAuthorityOnlyConsistingOfLocalIsAccepted()
     {
-        testAuthorityRejects( "local" );
+        testAuthorityIsAccepted( "local" );
     }
 
     public void testAuthorityWithEmptySubDomainIsRejected()
     {
-        testAuthorityRejects( "host..local" );
+        testAuthorityIsRejected( "host..com" );
     }
 
-    public void testAuthorityWithNonLocalDomainIsRejected()
+    public void testAuthorityWithNonLocalDomainIsAccepted()
     {
-        testAuthorityRejects( "www.example.org" );
+        testAuthorityIsAccepted( "www.example.org" );
     }
 
     public void testAuthorityWithLeadingHyphenIsRejected()
     {
-        testAuthorityRejects( "host.-organization.local" );
+        testAuthorityIsRejected( "host.-organization.com" );
     }
 
     public void testAuthorityWithTrailingHyphenIsRejected()
     {
-        testAuthorityRejects( "host.organization-.local" );
+        testAuthorityIsRejected( "host.organization-.com" );
     }
 
     public void testAuthorityWithTooLongSubDomainIsRejected()
     {
         String tooLongDomainName = "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffabcd";
         assertTrue( tooLongDomainName.length() == 64 );
-        testAuthorityRejects( "host." + tooLongDomainName + ".local" );
+        testAuthorityIsRejected( "host." + tooLongDomainName + ".com" );
     }
 
     private void testAuthorityIsAccepted( final String input )
@@ -196,13 +199,17 @@
 
     private boolean isValidAuthority( final String input )
     {
-        RegexValidator authority = UrlValidationUtil.configureLocalAuthorityValidator();
-        return authority.isValid( input );
+        return UrlValidationUtil.isValidUrl( "http://" + input );
     }
 
-    private void testAuthorityRejects( final String input )
+    private void testAuthorityIsRejected( final String input )
     {
         assertFalse( isValidAuthority( input ) );
     }
 
+    public static void main(String[] args) {
+		UrlValidator validator = UrlValidator.getInstance();
+		System.out.println(validator.isValid("http://host.organization.com:100000"));
+	}
+
 }