Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6C57917C47 for ; Tue, 13 Jan 2015 20:08:10 +0000 (UTC) Received: (qmail 47010 invoked by uid 500); 13 Jan 2015 20:07:52 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 46262 invoked by uid 500); 13 Jan 2015 20:07:52 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 43238 invoked by uid 99); 13 Jan 2015 20:07:49 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jan 2015 20:07:49 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 26796AC09F7 for ; Tue, 13 Jan 2015 20:07:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r936080 [34/44] - in /websites/production/commons/content/proper/commons-validator: ./ apidocs/ apidocs/org/apache/commons/validator/ apidocs/org/apache/commons/validator/class-use/ apidocs/org/apache/commons/validator/routines/ apidocs/org... Date: Tue, 13 Jan 2015 20:07:39 -0000 To: commits@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150113200749.26796AC09F7@hades.apache.org> Modified: websites/production/commons/content/proper/commons-validator/xref-test/org/apache/commons/validator/routines/UrlValidatorTest.html ============================================================================== --- websites/production/commons/content/proper/commons-validator/xref-test/org/apache/commons/validator/routines/UrlValidatorTest.html (original) +++ websites/production/commons/content/proper/commons-validator/xref-test/org/apache/commons/validator/routines/UrlValidatorTest.html Tue Jan 13 20:07:34 2015 @@ -1,6 +1,6 @@ - + UrlValidatorTest xref @@ -31,12 +31,12 @@ 23 /** 24 * Performs Validation Test for url validations. 25 * -26 * @version $Revision: 1128446 $ $Date: 2011-05-27 22:29:27 +0200 (Fr, 27 Mai 2011) $ +26 * @version $Revision: 1649975 $ 27 */ 28 public class UrlValidatorTest extends TestCase { 29 -30 private boolean printStatus = false; -31 private boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using. +30 private final boolean printStatus = false; +31 private final boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using. 32 33 public UrlValidatorTest(String testName) { 34 super(testName); @@ -63,359 +63,466 @@ 55 if (printStatus) { 56 System.out.print("\n testIsValidScheme() "); 57 } -58 String[] schemes = {"http", "gopher"}; -59 //UrlValidator urlVal = new UrlValidator(schemes,false,false,false); -60 UrlValidator urlVal = new UrlValidator(schemes, 0); -61 for (int sIndex = 0; sIndex < testScheme.length; sIndex++) { -62 ResultPair testPair = testScheme[sIndex]; -63 boolean result = urlVal.isValidScheme(testPair.item); -64 assertEquals(testPair.item, testPair.valid, result); -65 if (printStatus) { -66 if (result == testPair.valid) { -67 System.out.print('.'); -68 } else { -69 System.out.print('X'); -70 } -71 } -72 } -73 if (printStatus) { -74 System.out.println(); -75 } -76 -77 } -78 -79 /** -80 * Create set of tests by taking the testUrlXXX arrays and -81 * running through all possible permutations of their combinations. -82 * -83 * @param testObjects Used to create a url. -84 */ -85 public void testIsValid(Object[] testObjects, long options) { -86 UrlValidator urlVal = new UrlValidator(null, null, options); -87 assertTrue(urlVal.isValid("http://www.google.com")); -88 assertTrue(urlVal.isValid("http://www.google.com/")); -89 int statusPerLine = 60; -90 int printed = 0; -91 if (printIndex) { -92 statusPerLine = 6; -93 } -94 do { -95 StringBuffer testBuffer = new StringBuffer(); -96 boolean expected = true; -97 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { -98 int index = testPartsIndex[testPartsIndexIndex]; -99 ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex]; -100 testBuffer.append(part[index].item); -101 expected &= part[index].valid; -102 } -103 String url = testBuffer.toString(); -104 boolean result = urlVal.isValid(url); -105 assertEquals(url, expected, result); -106 if (printStatus) { -107 if (printIndex) { -108 System.out.print(testPartsIndextoString()); -109 } else { -110 if (result == expected) { -111 System.out.print('.'); -112 } else { -113 System.out.print('X'); -114 } -115 } -116 printed++; -117 if (printed == statusPerLine) { -118 System.out.println(); -119 printed = 0; -120 } -121 } -122 } while (incrementTestPartsIndex(testPartsIndex, testObjects)); -123 if (printStatus) { -124 System.out.println(); -125 } -126 } -127 -128 public void testValidator202() { -129 String[] schemes = {"http","https"}; -130 UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS); -131 assertTrue(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.org")); -132 } -133 -134 public void testValidator204() { -135 String[] schemes = {"http","https"}; -136 UrlValidator urlValidator = new UrlValidator(schemes); -137 assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5")); -138 } -139 -140 public void testValidator218() { -141 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); -142 assertTrue("parentheses should be valid in URLs", -143 validator.isValid("http://somewhere.com/pathxyz/file(1).html")); -144 } -145 -146 public void testValidator248() { -147 RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"}); -148 UrlValidator validator = new UrlValidator(regex, 0); -149 -150 assertTrue("localhost URL should validate", -151 validator.isValid("http://localhost/test/index.html")); -152 assertTrue("first.my-testing should validate", -153 validator.isValid("http://first.my-testing/test/index.html")); -154 assertTrue("sup3r.my-testing should validate", -155 validator.isValid("http://sup3r.my-testing/test/index.html")); -156 -157 assertFalse("broke.my-test should not validate", -158 validator.isValid("http://broke.my-test/test/index.html")); +58 //UrlValidator urlVal = new UrlValidator(schemes,false,false,false); +59 UrlValidator urlVal = new UrlValidator(schemes, 0); +60 for (int sIndex = 0; sIndex < testScheme.length; sIndex++) { +61 ResultPair testPair = testScheme[sIndex]; +62 boolean result = urlVal.isValidScheme(testPair.item); +63 assertEquals(testPair.item, testPair.valid, result); +64 if (printStatus) { +65 if (result == testPair.valid) { +66 System.out.print('.'); +67 } else { +68 System.out.print('X'); +69 } +70 } +71 } +72 if (printStatus) { +73 System.out.println(); +74 } +75 +76 } +77 +78 /** +79 * Create set of tests by taking the testUrlXXX arrays and +80 * running through all possible permutations of their combinations. +81 * +82 * @param testObjects Used to create a url. +83 */ +84 public void testIsValid(Object[] testObjects, long options) { +85 UrlValidator urlVal = new UrlValidator(null, null, options); +86 assertTrue(urlVal.isValid("http://www.google.com")); +87 assertTrue(urlVal.isValid("http://www.google.com/")); +88 int statusPerLine = 60; +89 int printed = 0; +90 if (printIndex) { +91 statusPerLine = 6; +92 } +93 do { +94 StringBuffer testBuffer = new StringBuffer(); +95 boolean expected = true; +96 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { +97 int index = testPartsIndex[testPartsIndexIndex]; +98 ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex]; +99 testBuffer.append(part[index].item); +100 expected &= part[index].valid; +101 } +102 String url = testBuffer.toString(); +103 boolean result = urlVal.isValid(url); +104 assertEquals(url, expected, result); +105 if (printStatus) { +106 if (printIndex) { +107 System.out.print(testPartsIndextoString()); +108 } else { +109 if (result == expected) { +110 System.out.print('.'); +111 } else { +112 System.out.print('X'); +113 } +114 } +115 printed++; +116 if (printed == statusPerLine) { +117 System.out.println(); +118 printed = 0; +119 } +120 } +121 } while (incrementTestPartsIndex(testPartsIndex, testObjects)); +122 if (printStatus) { +123 System.out.println(); +124 } +125 } +126 +127 public void testValidator202() { +128 String[] schemes = {"http","https"}; +129 UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS); +130 assertTrue(urlValidator.isValid("http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org")); +131 } +132 +133 public void testValidator204() { +134 String[] schemes = {"http","https"}; +135 UrlValidator urlValidator = new UrlValidator(schemes); +136 assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5")); +137 } +138 +139 public void testValidator218() { +140 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); +141 assertTrue("parentheses should be valid in URLs", +142 validator.isValid("http://somewhere.com/pathxyz/file(1).html")); +143 } +144 +145 public void testValidator235() { +146 String version = System.getProperty("java.version"); +147 if (version.compareTo("1.6") < 0) { +148 System.out.println("Cannot run Unicode IDN tests"); +149 return; // Cannot run the test +150 } +151 UrlValidator validator = new UrlValidator(); +152 assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("http://xn--d1abbgf6aiiy.xn--p1ai")); +153 assertTrue("президент.рф should validate", validator.isValid("http://президент.рф")); +154 assertTrue("www.b\u00fccher.ch should validate", validator.isValid("http://www.b\u00fccher.ch")); +155 assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("http://www.\uFFFD.ch")); +156 assertTrue("www.b\u00fccher.ch should validate", validator.isValid("ftp://www.b\u00fccher.ch")); +157 assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("ftp://www.\uFFFD.ch")); +158 } 159 -160 assertTrue("www.apache.org should still validate", -161 validator.isValid("http://www.apache.org/test/index.html")); -162 -163 // Now check using options -164 validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); -165 -166 assertTrue("localhost URL should validate", -167 validator.isValid("http://localhost/test/index.html")); -168 -169 assertTrue("machinename URL should validate", -170 validator.isValid("http://machinename/test/index.html")); -171 -172 assertTrue("www.apache.org should still validate", -173 validator.isValid("http://www.apache.org/test/index.html")); -174 } -175 -176 public void testValidator288() { -177 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); -178 -179 assertTrue("hostname should validate", -180 validator.isValid("http://hostname")); -181 -182 assertTrue("hostname with path should validate", -183 validator.isValid("http://hostname/test/index.html")); -184 -185 assertTrue("localhost URL should validate", -186 validator.isValid("http://localhost/test/index.html")); -187 -188 assertFalse("first.my-testing should not validate", -189 validator.isValid("http://first.my-testing/test/index.html")); -190 -191 assertFalse("broke.hostname should not validate", -192 validator.isValid("http://broke.hostname/test/index.html")); -193 -194 assertTrue("www.apache.org should still validate", -195 validator.isValid("http://www.apache.org/test/index.html")); -196 -197 // Turn it off, and check -198 validator = new UrlValidator(0); -199 -200 assertFalse("hostname should no longer validate", -201 validator.isValid("http://hostname")); -202 -203 assertFalse("localhost URL should no longer validate", -204 validator.isValid("http://localhost/test/index.html")); -205 -206 assertTrue("www.apache.org should still validate", -207 validator.isValid("http://www.apache.org/test/index.html")); -208 } -209 -210 public void testValidator276() { -211 // file:// isn't allowed by default -212 UrlValidator validator = new UrlValidator(); -213 -214 assertTrue("http://apache.org/ should be allowed by default", -215 validator.isValid("http://www.apache.org/test/index.html")); -216 -217 assertFalse("file:///c:/ shouldn't be allowed by default", -218 validator.isValid("file:///C:/some.file")); +160 public void testValidator248() { +161 RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"}); +162 UrlValidator validator = new UrlValidator(regex, 0); +163 +164 assertTrue("localhost URL should validate", +165 validator.isValid("http://localhost/test/index.html")); +166 assertTrue("first.my-testing should validate", +167 validator.isValid("http://first.my-testing/test/index.html")); +168 assertTrue("sup3r.my-testing should validate", +169 validator.isValid("http://sup3r.my-testing/test/index.html")); +170 +171 assertFalse("broke.my-test should not validate", +172 validator.isValid("http://broke.my-test/test/index.html")); +173 +174 assertTrue("www.apache.org should still validate", +175 validator.isValid("http://www.apache.org/test/index.html")); +176 +177 // Now check using options +178 validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); +179 +180 assertTrue("localhost URL should validate", +181 validator.isValid("http://localhost/test/index.html")); +182 +183 assertTrue("machinename URL should validate", +184 validator.isValid("http://machinename/test/index.html")); +185 +186 assertTrue("www.apache.org should still validate", +187 validator.isValid("http://www.apache.org/test/index.html")); +188 } +189 +190 public void testValidator288() { +191 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); +192 +193 assertTrue("hostname should validate", +194 validator.isValid("http://hostname")); +195 +196 assertTrue("hostname with path should validate", +197 validator.isValid("http://hostname/test/index.html")); +198 +199 assertTrue("localhost URL should validate", +200 validator.isValid("http://localhost/test/index.html")); +201 +202 assertFalse("first.my-testing should not validate", +203 validator.isValid("http://first.my-testing/test/index.html")); +204 +205 assertFalse("broke.hostname should not validate", +206 validator.isValid("http://broke.hostname/test/index.html")); +207 +208 assertTrue("www.apache.org should still validate", +209 validator.isValid("http://www.apache.org/test/index.html")); +210 +211 // Turn it off, and check +212 validator = new UrlValidator(0); +213 +214 assertFalse("hostname should no longer validate", +215 validator.isValid("http://hostname")); +216 +217 assertFalse("localhost URL should no longer validate", +218 validator.isValid("http://localhost/test/index.html")); 219 -220 assertFalse("file:///c:\\ shouldn't be allowed by default", -221 validator.isValid("file:///C:\\some.file")); -222 -223 assertFalse("file:///etc/ shouldn't be allowed by default", -224 validator.isValid("file:///etc/hosts")); -225 -226 assertFalse("file://localhost/etc/ shouldn't be allowed by default", -227 validator.isValid("file://localhost/etc/hosts")); -228 -229 assertFalse("file://localhost/c:/ shouldn't be allowed by default", -230 validator.isValid("file://localhost/c:/some.file")); -231 -232 // Turn it on, and check -233 // Note - we need to enable local urls when working with file: -234 validator = new UrlValidator(new String[] {"http","file"}, UrlValidator.ALLOW_LOCAL_URLS); -235 -236 assertTrue("http://apache.org/ should be allowed by default", -237 validator.isValid("http://www.apache.org/test/index.html")); -238 -239 assertTrue("file:///c:/ should now be allowed", -240 validator.isValid("file:///C:/some.file")); -241 -242 // Currently, we don't support the c:\ form -243 assertFalse("file:///c:\\ shouldn't be allowed", -244 validator.isValid("file:///C:\\some.file")); +220 assertTrue("www.apache.org should still validate", +221 validator.isValid("http://www.apache.org/test/index.html")); +222 } +223 +224 public void testValidator276() { +225 // file:// isn't allowed by default +226 UrlValidator validator = new UrlValidator(); +227 +228 assertTrue("http://apache.org/ should be allowed by default", +229 validator.isValid("http://www.apache.org/test/index.html")); +230 +231 assertFalse("file:///c:/ shouldn't be allowed by default", +232 validator.isValid("file:///C:/some.file")); +233 +234 assertFalse("file:///c:\\ shouldn't be allowed by default", +235 validator.isValid("file:///C:\\some.file")); +236 +237 assertFalse("file:///etc/ shouldn't be allowed by default", +238 validator.isValid("file:///etc/hosts")); +239 +240 assertFalse("file://localhost/etc/ shouldn't be allowed by default", +241 validator.isValid("file://localhost/etc/hosts")); +242 +243 assertFalse("file://localhost/c:/ shouldn't be allowed by default", +244 validator.isValid("file://localhost/c:/some.file")); 245 -246 assertTrue("file:///etc/ should now be allowed", -247 validator.isValid("file:///etc/hosts")); -248 -249 assertTrue("file://localhost/etc/ should now be allowed", -250 validator.isValid("file://localhost/etc/hosts")); -251 -252 assertTrue("file://localhost/c:/ should now be allowed", -253 validator.isValid("file://localhost/c:/some.file")); -254 -255 // These are never valid -256 assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/", -257 validator.isValid("file://C:/some.file")); -258 -259 assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/", -260 validator.isValid("file://C:\\some.file")); -261 } -262 -263 -264 static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) { -265 boolean carry = true; //add 1 to lowest order part. -266 boolean maxIndex = true; -267 for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) { -268 int index = testPartsIndex[testPartsIndexIndex]; -269 ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex]; -270 if (carry) { -271 if (index < part.length - 1) { -272 index++; -273 testPartsIndex[testPartsIndexIndex] = index; -274 carry = false; -275 } else { -276 testPartsIndex[testPartsIndexIndex] = 0; -277 carry = true; -278 } -279 } -280 maxIndex &= (index == (part.length - 1)); -281 } -282 -283 -284 return (!maxIndex); -285 } -286 -287 private String testPartsIndextoString() { -288 StringBuffer carryMsg = new StringBuffer("{"); -289 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) { -290 carryMsg.append(testPartsIndex[testPartsIndexIndex]); -291 if (testPartsIndexIndex < testPartsIndex.length - 1) { -292 carryMsg.append(','); -293 } else { -294 carryMsg.append('}'); -295 } -296 } -297 return carryMsg.toString(); -298 -299 } -300 -301 public void testValidateUrl() { -302 assertTrue(true); -303 } -304 -305 /** -306 * Only used to debug the unit tests. -307 * @param argv -308 */ -309 public static void main(String[] argv) { -310 -311 UrlValidatorTest fct = new UrlValidatorTest("url test"); -312 fct.setUp(); -313 fct.testIsValid(); -314 fct.testIsValidScheme(); -315 } -316 //-------------------- Test data for creating a composite URL -317 /** -318 * The data given below approximates the 4 parts of a URL -319 * <scheme>://<authority><path>?<query> except that the port number -320 * is broken out of authority to increase the number of permutations. -321 * A complete URL is composed of a scheme+authority+port+path+query, -322 * all of which must be individually valid for the entire URL to be considered -323 * valid. -324 */ -325 ResultPair[] testUrlScheme = {new ResultPair("http://", true), -326 new ResultPair("ftp://", true), -327 new ResultPair("h3t://", true), -328 new ResultPair("3ht://", false), -329 new ResultPair("http:/", false), -330 new ResultPair("http:", false), -331 new ResultPair("http/", false), -332 new ResultPair("://", false), -333 new ResultPair("", true)}; -334 -335 ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true), -336 new ResultPair("go.com", true), -337 new ResultPair("go.au", true), -338 new ResultPair("0.0.0.0", true), -339 new ResultPair("255.255.255.255", true), -340 new ResultPair("256.256.256.256", false), -341 new ResultPair("255.com", true), -342 new ResultPair("1.2.3.4.5", false), -343 new ResultPair("1.2.3.4.", false), -344 new ResultPair("1.2.3", false), -345 new ResultPair(".1.2.3.4", false), -346 new ResultPair("go.a", false), -347 new ResultPair("go.a1a", false), -348 new ResultPair("go.cc", true), -349 new ResultPair("go.1aa", false), -350 new ResultPair("aaa.", false), -351 new ResultPair(".aaa", false), -352 new ResultPair("aaa", false), -353 new ResultPair("", false) -354 }; -355 ResultPair[] testUrlPort = {new ResultPair(":80", true), -356 new ResultPair(":65535", true), -357 new ResultPair(":0", true), -358 new ResultPair("", true), -359 new ResultPair(":-1", false), -360 new ResultPair(":65636", true), -361 new ResultPair(":65a", false) -362 }; -363 ResultPair[] testPath = {new ResultPair("/test1", true), -364 new ResultPair("/t123", true), -365 new ResultPair("/$23", true), -366 new ResultPair("/..", false), -367 new ResultPair("/../", false), -368 new ResultPair("/test1/", true), -369 new ResultPair("", true), -370 new ResultPair("/test1/file", true), -371 new ResultPair("/..//file", false), -372 new ResultPair("/test1//file", false) -373 }; -374 //Test allow2slash, noFragment -375 ResultPair[] testUrlPathOptions = {new ResultPair("/test1", true), -376 new ResultPair("/t123", true), -377 new ResultPair("/$23", true), -378 new ResultPair("/..", false), -379 new ResultPair("/../", false), -380 new ResultPair("/test1/", true), -381 new ResultPair("/#", false), -382 new ResultPair("", true), -383 new ResultPair("/test1/file", true), -384 new ResultPair("/t123/file", true), -385 new ResultPair("/$23/file", true), -386 new ResultPair("/../file", false), -387 new ResultPair("/..//file", false), -388 new ResultPair("/test1//file", true), -389 new ResultPair("/#/file", false) -390 }; -391 -392 ResultPair[] testUrlQuery = {new ResultPair("?action=view", true), -393 new ResultPair("?action=edit&mode=up", true), -394 new ResultPair("", true) -395 }; -396 -397 Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery}; -398 Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery}; -399 int[] testPartsIndex = {0, 0, 0, 0, 0}; -400 -401 //---------------- Test data for individual url parts ---------------- -402 ResultPair[] testScheme = {new ResultPair("http", true), -403 new ResultPair("ftp", false), -404 new ResultPair("httpd", false), -405 new ResultPair("telnet", false)}; -406 -407 -408 } +246 // Turn it on, and check +247 // Note - we need to enable local urls when working with file: +248 validator = new UrlValidator(new String[] {"http","file"}, UrlValidator.ALLOW_LOCAL_URLS); +249 +250 assertTrue("http://apache.org/ should be allowed by default", +251 validator.isValid("http://www.apache.org/test/index.html")); +252 +253 assertTrue("file:///c:/ should now be allowed", +254 validator.isValid("file:///C:/some.file")); +255 +256 // Currently, we don't support the c:\ form +257 assertFalse("file:///c:\\ shouldn't be allowed", +258 validator.isValid("file:///C:\\some.file")); +259 +260 assertTrue("file:///etc/ should now be allowed", +261 validator.isValid("file:///etc/hosts")); +262 +263 assertTrue("file://localhost/etc/ should now be allowed", +264 validator.isValid("file://localhost/etc/hosts")); +265 +266 assertTrue("file://localhost/c:/ should now be allowed", +267 validator.isValid("file://localhost/c:/some.file")); +268 +269 // These are never valid +270 assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/", +271 validator.isValid("file://C:/some.file")); +272 +273 assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/", +274 validator.isValid("file://C:\\some.file")); +275 } +276 +277 +278 public void testValidator309() { +279 UrlValidator urlValidator = new UrlValidator(); +280 assertTrue(urlValidator.isValid("http://sample.ondemand.com/")); +281 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/")); +282 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/")); +283 urlValidator = new UrlValidator(new String[] {"HTTP","HTTPS"}); +284 assertTrue(urlValidator.isValid("http://sample.ondemand.com/")); +285 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/")); +286 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/")); +287 } +288 +289 public void testValidator339(){ +290 UrlValidator urlValidator = new UrlValidator(); +291 assertTrue(urlValidator.isValid("http://www.cnn.com/WORLD/?hpt=sitenav")); // without +292 assertTrue(urlValidator.isValid("http://www.cnn.com./WORLD/?hpt=sitenav")); // with +293 assertFalse(urlValidator.isValid("http://www.cnn.com../")); // doubly dotty +294 assertFalse(urlValidator.isValid("http://www.cnn.invalid/")); +295 assertFalse(urlValidator.isValid("http://www.cnn.invalid./")); // check . does not affect invalid domains [... 228 lines stripped ...]