You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rg...@apache.org on 2015/10/25 07:03:42 UTC
svn commit: r1710414 - in /commons/proper/validator/trunk/src:
changes/changes.xml
main/java/org/apache/commons/validator/routines/EmailValidator.java
test/java/org/apache/commons/validator/EmailTest.java
Author: rgoers
Date: Sun Oct 25 06:03:42 2015
New Revision: 1710414
URL: http://svn.apache.org/viewvc?rev=1710414&view=rev
Log:
VALIDATOR-376 Revert the default behavior to the state prior to VALIDATOR-273.
Modified:
commons/proper/validator/trunk/src/changes/changes.xml
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/EmailTest.java
Modified: commons/proper/validator/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/changes/changes.xml?rev=1710414&r1=1710413&r2=1710414&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Sun Oct 25 06:03:42 2015
@@ -43,6 +43,11 @@ The <action> type attribute can be add,u
<body>
<release version="1.5.0" date="tba" description="tba">
+ <action issue="VALIDATOR-376" type="fix" dev="rgoers">
+ Revert EmailValidator to handle top level domains to the behavior prior to VALIDATOR-273. Allow an optional
+ behavior to allow the behavior VALIDATOR-273 implemented. Note that this is a behavioral change for users
+ of version 1.4.1, but not for anyone upgrading from a release prior to that.
+ </action>
<action issue="VALIDATOR-371" type="remove">Drop the Javascript code entirely</action>
<action issue="VALIDATOR-362" dev="britter" type="fix" due-to="Teo Bran">
Local part of the email address should not be longer than 64 bytes
Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java?rev=1710414&r1=1710413&r2=1710414&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java (original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/EmailValidator.java Sun Oct 25 06:03:42 2015
@@ -51,18 +51,32 @@ public class EmailValidator implements S
private static final Pattern USER_PATTERN = Pattern.compile(USER_REGEX);
private final boolean allowLocal;
+ private final boolean allowTld;
/**
* Singleton instance of this class, which
* doesn't consider local addresses as valid.
*/
- private static final EmailValidator EMAIL_VALIDATOR = new EmailValidator(false);
+ private static final EmailValidator EMAIL_VALIDATOR = new EmailValidator(false, false);
+
+ /**
+ * Singleton instance of this class, which
+ * doesn't consider local addresses as valid.
+ */
+ private static final EmailValidator EMAIL_VALIDATOR_WITH_TLD = new EmailValidator(false, true);
/**
* Singleton instance of this class, which does
* consider local addresses valid.
*/
- private static final EmailValidator EMAIL_VALIDATOR_WITH_LOCAL = new EmailValidator(true);
+ private static final EmailValidator EMAIL_VALIDATOR_WITH_LOCAL = new EmailValidator(true, false);
+
+
+ /**
+ * Singleton instance of this class, which does
+ * consider local addresses valid.
+ */
+ private static final EmailValidator EMAIL_VALIDATOR_WITH_LOCAL_WITH_TLD = new EmailValidator(true, true);
/**
* Returns the Singleton instance of this validator.
@@ -80,11 +94,42 @@ public class EmailValidator implements S
* @param allowLocal Should local addresses be considered valid?
* @return singleton instance of this validator
*/
- public static EmailValidator getInstance(boolean allowLocal) {
+ public static EmailValidator getInstance(boolean allowLocal, boolean allowTld) {
if(allowLocal) {
- return EMAIL_VALIDATOR_WITH_LOCAL;
+ if (allowTld) {
+ return EMAIL_VALIDATOR_WITH_LOCAL_WITH_TLD;
+ } else {
+ return EMAIL_VALIDATOR_WITH_LOCAL;
+ }
+ } else {
+ if (allowTld) {
+ return EMAIL_VALIDATOR_WITH_TLD;
+ } else {
+ return EMAIL_VALIDATOR;
+ }
}
- return EMAIL_VALIDATOR;
+ }
+
+ /**
+ * Returns the Singleton instance of this validator,
+ * with local validation as required.
+ *
+ * @param allowLocal Should local addresses be considered valid?
+ * @return singleton instance of this validator
+ */
+ public static EmailValidator getInstance(boolean allowLocal) {
+ return getInstance(allowLocal, false);
+ }
+
+ /**
+ * Protected constructor for subclasses to use.
+ *
+ * @param allowLocal Should local addresses be considered valid?
+ */
+ protected EmailValidator(boolean allowLocal, boolean allowTld) {
+ super();
+ this.allowLocal = allowLocal;
+ this.allowTld = allowTld;
}
/**
@@ -95,6 +140,7 @@ public class EmailValidator implements S
protected EmailValidator(boolean allowLocal) {
super();
this.allowLocal = allowLocal;
+ this.allowTld = false;
}
/**
@@ -148,8 +194,11 @@ public class EmailValidator implements S
// Domain is symbolic name
DomainValidator domainValidator =
DomainValidator.getInstance(allowLocal);
- return domainValidator.isValid(domain) ||
- domainValidator.isValidTld(domain);
+ if (allowTld) {
+ return domainValidator.isValid(domain) || domainValidator.isValidTld(domain);
+ } else {
+ return domainValidator.isValid(domain);
+ }
}
/**
Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/EmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/EmailTest.java?rev=1710414&r1=1710413&r2=1710414&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/EmailTest.java (original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/EmailTest.java Sun Oct 25 06:03:42 2015
@@ -218,7 +218,12 @@ public class EmailTest extends AbstractC
ValueBean info = new ValueBean();
info.setValue("m@de");
- valueTest(info, true);
+ valueTest(info, false);
+
+ org.apache.commons.validator.routines.EmailValidator validator =
+ org.apache.commons.validator.routines.EmailValidator.getInstance(true, true);
+ boolean result = validator.isValid("m@de");
+ assertTrue("Result should have been true", result);
}