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 F37A2104A9 for ; Fri, 26 Dec 2014 12:51:15 +0000 (UTC) Received: (qmail 61814 invoked by uid 500); 26 Dec 2014 12:51:11 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 61476 invoked by uid 500); 26 Dec 2014 12:51:11 -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 60894 invoked by uid 99); 26 Dec 2014 12:51:11 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Dec 2014 12:51:11 +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 03B88AC1100 for ; Fri, 26 Dec 2014 12:51:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r934044 [16/18] - in /websites/production/commons/content/proper/commons-validator: ./ apidocs/ apidocs/org/apache/commons/validator/ apidocs/org/apache/commons/validator/routines/ apidocs/org/apache/commons/validator/routines/checkdigit/ a... Date: Fri, 26 Dec 2014 12:51:04 -0000 To: commits@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141226125109.03B88AC1100@hades.apache.org> Modified: websites/production/commons/content/proper/commons-validator/xref/org/apache/commons/validator/UrlValidator.html ============================================================================== --- websites/production/commons/content/proper/commons-validator/xref/org/apache/commons/validator/UrlValidator.html (original) +++ websites/production/commons/content/proper/commons-validator/xref/org/apache/commons/validator/UrlValidator.html Fri Dec 26 12:51:02 2014 @@ -79,7 +79,7 @@ 71 * Uniform Resource Identifiers (URI): Generic Syntax 72 * </a> 73 * -74 * @version $Revision: 1647900 $ $Date: 2014-12-25 16:03:53 +0100 (Do, 25 Dez 2014) $ +74 * @version $Revision: 1647964 $ $Date: 2014-12-26 13:33:35 +0100 (Fr, 26 Dez 2014) $ 75 * @since Validator 1.1 76 * @deprecated Use the new UrlValidator in the routines package. This class 77 * will be removed in a future release. @@ -301,185 +301,178 @@ 293 return false; 294 } 295 -296 if (this.options.isOff(ALLOW_ALL_SCHEMES)) { -297 -298 if (!this.allowedSchemes.contains(scheme)) { -299 return false; -300 } -301 } +296 if (options.isOff(ALLOW_ALL_SCHEMES) && !allowedSchemes.contains(scheme)) { +297 return false; +298 } +299 +300 return true; +301 } 302 -303 return true; -304 } -305 -306 /** -307 * Returns true if the authority is properly formatted. An authority is the combination -308 * of hostname and port. A <code>null</code> authority value is considered invalid. -309 * @param authority Authority value to validate. -310 * @return true if authority (hostname and port) is valid. -311 */ -312 protected boolean isValidAuthority(String authority) { -313 if (authority == null) { -314 return false; -315 } +303 /** +304 * Returns true if the authority is properly formatted. An authority is the combination +305 * of hostname and port. A <code>null</code> authority value is considered invalid. +306 * @param authority Authority value to validate. +307 * @return true if authority (hostname and port) is valid. +308 */ +309 protected boolean isValidAuthority(String authority) { +310 if (authority == null) { +311 return false; +312 } +313 +314 InetAddressValidator inetAddressValidator = +315 InetAddressValidator.getInstance(); 316 -317 InetAddressValidator inetAddressValidator = -318 InetAddressValidator.getInstance(); -319 -320 Matcher authorityMatcher = AUTHORITY_PATTERN.matcher(authority); -321 if (!authorityMatcher.matches()) { -322 return false; -323 } -324 -325 boolean hostname = false; -326 // check if authority is IP address or hostname -327 String hostIP = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP); -328 boolean ipV4Address = inetAddressValidator.isValid(hostIP); -329 -330 if (!ipV4Address) { -331 // Domain is hostname name -332 hostname = DOMAIN_PATTERN.matcher(hostIP).matches(); -333 } -334 -335 //rightmost hostname will never start with a digit. -336 if (hostname) { -337 // LOW-TECH FIX FOR VALIDATOR-202 -338 // TODO: Rewrite to use ArrayList and .add semantics: see VALIDATOR-203 -339 char[] chars = hostIP.toCharArray(); -340 int size = 1; -341 for(int i=0; i<chars.length; i++) { -342 if(chars[i] == '.') { -343 size++; -344 } -345 } -346 String[] domainSegment = new String[size]; -347 boolean match = true; -348 int segmentCount = 0; -349 int segmentLength = 0; -350 -351 while (match) { -352 Matcher atomMatcher = ATOM_PATTERN.matcher(hostIP); -353 match = atomMatcher.matches(); -354 if (match) { -355 domainSegment[segmentCount] = atomMatcher.group(1); -356 segmentLength = domainSegment[segmentCount].length() + 1; -357 hostIP = -358 (segmentLength >= hostIP.length()) -359 ? "" -360 : hostIP.substring(segmentLength); -361 -362 segmentCount++; -363 } -364 } -365 String topLevel = domainSegment[segmentCount - 1]; -366 if (topLevel.length() < 2 || topLevel.length() > 4) { -367 return false; -368 } -369 -370 // First letter of top level must be a alpha -371 if (!ALPHA_PATTERN.matcher(topLevel.substring(0, 1)).matches()) { -372 return false; -373 } -374 -375 // Make sure there's a host name preceding the authority. -376 if (segmentCount < 2) { -377 return false; -378 } -379 } -380 -381 if (!hostname && !ipV4Address) { -382 return false; -383 } -384 -385 String port = authorityMatcher.group(PARSE_AUTHORITY_PORT); -386 if (port != null) { -387 if (!PORT_PATTERN.matcher(port).matches()) { -388 return false; -389 } +317 Matcher authorityMatcher = AUTHORITY_PATTERN.matcher(authority); +318 if (!authorityMatcher.matches()) { +319 return false; +320 } +321 +322 boolean hostname = false; +323 // check if authority is IP address or hostname +324 String hostIP = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP); +325 boolean ipV4Address = inetAddressValidator.isValid(hostIP); +326 +327 if (!ipV4Address) { +328 // Domain is hostname name +329 hostname = DOMAIN_PATTERN.matcher(hostIP).matches(); +330 } +331 +332 //rightmost hostname will never start with a digit. +333 if (hostname) { +334 // LOW-TECH FIX FOR VALIDATOR-202 +335 // TODO: Rewrite to use ArrayList and .add semantics: see VALIDATOR-203 +336 char[] chars = hostIP.toCharArray(); +337 int size = 1; +338 for(int i=0; i<chars.length; i++) { +339 if(chars[i] == '.') { +340 size++; +341 } +342 } +343 String[] domainSegment = new String[size]; +344 boolean match = true; +345 int segmentCount = 0; +346 int segmentLength = 0; +347 +348 while (match) { +349 Matcher atomMatcher = ATOM_PATTERN.matcher(hostIP); +350 match = atomMatcher.matches(); +351 if (match) { +352 domainSegment[segmentCount] = atomMatcher.group(1); +353 segmentLength = domainSegment[segmentCount].length() + 1; +354 hostIP = +355 (segmentLength >= hostIP.length()) +356 ? "" +357 : hostIP.substring(segmentLength); +358 +359 segmentCount++; +360 } +361 } +362 String topLevel = domainSegment[segmentCount - 1]; +363 if (topLevel.length() < 2 || topLevel.length() > 4) { +364 return false; +365 } +366 +367 // First letter of top level must be a alpha +368 if (!ALPHA_PATTERN.matcher(topLevel.substring(0, 1)).matches()) { +369 return false; +370 } +371 +372 // Make sure there's a host name preceding the authority. +373 if (segmentCount < 2) { +374 return false; +375 } +376 } +377 +378 if (!hostname && !ipV4Address) { +379 return false; +380 } +381 +382 String port = authorityMatcher.group(PARSE_AUTHORITY_PORT); +383 if (port != null && !PORT_PATTERN.matcher(port).matches()) { +384 return false; +385 } +386 +387 String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA); +388 if (!GenericValidator.isBlankOrNull(extra)) { +389 return false; 390 } 391 -392 String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA); -393 if (!GenericValidator.isBlankOrNull(extra)) { -394 return false; -395 } -396 -397 return true; -398 } -399 -400 /** -401 * Returns true if the path is valid. A <code>null</code> value is considered invalid. -402 * @param path Path value to validate. -403 * @return true if path is valid. -404 */ -405 protected boolean isValidPath(String path) { -406 if (path == null) { -407 return false; -408 } -409 -410 if (!PATH_PATTERN.matcher(path).matches()) { +392 return true; +393 } +394 +395 /** +396 * Returns true if the path is valid. A <code>null</code> value is considered invalid. +397 * @param path Path value to validate. +398 * @return true if path is valid. +399 */ +400 protected boolean isValidPath(String path) { +401 if (path == null) { +402 return false; +403 } +404 +405 if (!PATH_PATTERN.matcher(path).matches()) { +406 return false; +407 } +408 +409 int slash2Count = countToken("//", path); +410 if (options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) { 411 return false; 412 } 413 -414 int slash2Count = countToken("//", path); -415 if (this.options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) { -416 return false; -417 } -418 -419 int slashCount = countToken("/", path); -420 int dot2Count = countToken("..", path); -421 if (dot2Count > 0) { -422 if ((slashCount - slash2Count - 1) <= dot2Count) { -423 return false; -424 } -425 } -426 -427 return true; -428 } -429 -430 /** -431 * Returns true if the query is null or it's a properly formatted query string. -432 * @param query Query value to validate. -433 * @return true if query is valid. -434 */ -435 protected boolean isValidQuery(String query) { -436 if (query == null) { -437 return true; -438 } -439 -440 return QUERY_PATTERN.matcher(query).matches(); -441 } -442 -443 /** -444 * Returns true if the given fragment is null or fragments are allowed. -445 * @param fragment Fragment value to validate. -446 * @return true if fragment is valid. -447 */ -448 protected boolean isValidFragment(String fragment) { -449 if (fragment == null) { -450 return true; -451 } -452 -453 return this.options.isOff(NO_FRAGMENTS); -454 } -455 -456 /** -457 * Returns the number of times the token appears in the target. -458 * @param token Token value to be counted. -459 * @param target Target value to count tokens in. -460 * @return the number of tokens. -461 */ -462 protected int countToken(String token, String target) { -463 int tokenIndex = 0; -464 int count = 0; -465 while (tokenIndex != -1) { -466 tokenIndex = target.indexOf(token, tokenIndex); -467 if (tokenIndex > -1) { -468 tokenIndex++; -469 count++; -470 } -471 } -472 return count; -473 } -474 } +414 int slashCount = countToken("/", path); +415 int dot2Count = countToken("..", path); +416 if (dot2Count > 0 && (slashCount - slash2Count - 1) <= dot2Count){ +417 return false; +418 } +419 +420 return true; +421 } +422 +423 /** +424 * Returns true if the query is null or it's a properly formatted query string. +425 * @param query Query value to validate. +426 * @return true if query is valid. +427 */ +428 protected boolean isValidQuery(String query) { +429 if (query == null) { +430 return true; +431 } +432 +433 return QUERY_PATTERN.matcher(query).matches(); +434 } +435 +436 /** +437 * Returns true if the given fragment is null or fragments are allowed. +438 * @param fragment Fragment value to validate. +439 * @return true if fragment is valid. +440 */ +441 protected boolean isValidFragment(String fragment) { +442 if (fragment == null) { +443 return true; +444 } +445 +446 return options.isOff(NO_FRAGMENTS); +447 } +448 +449 /** +450 * Returns the number of times the token appears in the target. +451 * @param token Token value to be counted. +452 * @param target Target value to count tokens in. +453 * @return the number of tokens. +454 */ +455 protected int countToken(String token, String target) { +456 int tokenIndex = 0; +457 int count = 0; +458 while (tokenIndex != -1) { +459 tokenIndex = target.indexOf(token, tokenIndex); +460 if (tokenIndex > -1) { +461 tokenIndex++; +462 count++; +463 } +464 } +465 return count; +466 } +467 }