Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 47980 invoked from network); 14 Nov 2007 19:37:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Nov 2007 19:37:21 -0000 Received: (qmail 85453 invoked by uid 500); 14 Nov 2007 19:37:08 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 84995 invoked by uid 500); 14 Nov 2007 19:37:07 -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 84981 invoked by uid 99); 14 Nov 2007 19:37:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Nov 2007 11:37:07 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Nov 2007 19:36:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A03001A9832; Wed, 14 Nov 2007 11:36:50 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r595020 - in /commons/proper/validator/trunk/src: main/java/org/apache/commons/validator/routines/UrlValidator.java test/java/org/apache/commons/validator/routines/UrlValidatorTest.java Date: Wed, 14 Nov 2007 19:36:49 -0000 To: commits@commons.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071114193650.A03001A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: niallp Date: Wed Nov 14 11:36:45 2007 New Revision: 595020 URL: http://svn.apache.org/viewvc?rev=595020&view=rev Log: VALIDATOR-248 - simplify the alternative regular expr validation of host names Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java?rev=595020&r1=595019&r2=595020&view=diff ============================================================================== --- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java (original) +++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java Wed Nov 14 11:36:45 2007 @@ -33,10 +33,6 @@ * included then fragments are flagged as illegal. *
  • ALLOW_ALL_SCHEMES - [FALSE] By default only http, https, and ftp are * considered valid schemes. Enabling this option will let any scheme pass validation.
  • - *
  • MANUAL_AUTHORITY_VALIDATION - [FALSE] By default, URL authorities must be IANA-defined - * domain names. Enabling this option and providing an array of authority validators - * will validate the URL's authority against the regexes; if it matches, the authority - * validation will succeed. If no match is found, domain name validation is used.
  • * *

    Originally based in on php script by Debbie Dyer, validation.php v1.2b, Date: 03/07/02, * http://javascript.internet.com. However, this validation now bears little resemblance @@ -92,12 +88,6 @@ */ public static final long NO_FRAGMENTS = 1 << 2; - /** - * If enabled, consults a provided list of RegexValidators when validating - * the URL authority. This allows names like "localhost", "test-machine", etc. - */ - public static final long MANUAL_AUTHORITY_VALIDATION = 1 << 3; - // Drop numeric, and "+-." for now private static final String AUTHORITY_CHARS_REGEX = "\\p{Alnum}\\-\\."; @@ -171,7 +161,7 @@ * Regular expressions used to manually validate authorities if IANA * domain name validation isn't desired. */ - private final RegexValidator[] authorityValidators; + private final RegexValidator authorityValidator; /** * If no schemes are provided, default to this set. @@ -233,27 +223,26 @@ /** * Initialize a UrlValidator with the given validation options. - * @param authorityValidators regexes used to validate the authority part; - * see {@link #MANUAL_AUTHORITY_VALIDATION} + * @param authorityValidator Regular expression validator used to validate the authority part * @param options Validation options. Set using the public constants of this class. * To set multiple options, simply add them together: *

    ALLOW_2_SLASHES + NO_FRAGMENTS

    * enables both of those options. */ - public UrlValidator(RegexValidator[] authorityValidators, long options) { - this(null, authorityValidators, options); + public UrlValidator(RegexValidator authorityValidator, long options) { + this(null, authorityValidator, options); } /** * Customizable constructor. Validation behavior is modifed by passing in options. * @param schemes the set of valid schemes - * @param authorityValidators the set of regexes to manually validate the scheme against + * @param authorityValidator Regular expression validator used to validate the authority part * @param options Validation options. Set using the public constants of this class. * To set multiple options, simply add them together: *

    ALLOW_2_SLASHES + NO_FRAGMENTS

    * enables both of those options. */ - public UrlValidator(String[] schemes, RegexValidator[] authorityValidators, long options) { + public UrlValidator(String[] schemes, RegexValidator authorityValidator, long options) { this.options = options; if (isOn(ALLOW_ALL_SCHEMES)) { @@ -266,11 +255,7 @@ this.allowedSchemes.addAll(Arrays.asList(schemes)); } - if (isOn(MANUAL_AUTHORITY_VALIDATION)) { - this.authorityValidators = authorityValidators; - } else { - this.authorityValidators = null; - } + this.authorityValidator = authorityValidator; } @@ -358,16 +343,9 @@ } // check manual authority validation if specified - if (isOn(MANUAL_AUTHORITY_VALIDATION)) { - if (authorityValidators == null) { - throw new IllegalStateException( - "manual authority validation enabled, but no authority validators specified"); - } - - for (int i = 0; i < authorityValidators.length; i++) { - if (authorityValidators[i].isValid(authority)) { - return true; - } + if (authorityValidator != null) { + if (authorityValidator.isValid(authority)) { + return true; } } Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java?rev=595020&r1=595019&r2=595020&view=diff ============================================================================== --- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java (original) +++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java Wed Nov 14 11:36:45 2007 @@ -153,11 +153,8 @@ } public void testValidator248() { - RegexValidator[] regex = new RegexValidator[] { - new RegexValidator("localhost"), - new RegexValidator(".*\\.my-testing") - }; - UrlValidator validator = new UrlValidator(regex, UrlValidator.MANUAL_AUTHORITY_VALIDATION); + RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"}); + UrlValidator validator = new UrlValidator(regex, 0); assertTrue("localhost URL should validate", validator.isValid("http://localhost/test/index.html"));