Skip to content

Commit 67719fb

Browse files
author
graeme
committed
fix for GRAILS-2669
git-svn-id: https://svn.codehaus.org/grails/trunk@6815 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 45a2f64 commit 67719fb

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/commons/org/codehaus/groovy/grails/validation/EmailConstraint.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
*/
1515
package org.codehaus.groovy.grails.validation;
1616

17-
import org.springframework.validation.Errors;
17+
import org.apache.commons.lang.StringUtils;
1818
import org.apache.commons.validator.EmailValidator;
19+
import org.springframework.validation.Errors;
1920

2021
/**
2122
* A Constraint that validates an email address
@@ -57,7 +58,9 @@ protected void processValidate(Object target, Object propertyValue, Errors error
5758
if(email) {
5859
EmailValidator emailValidator = EmailValidator.getInstance();
5960
Object[] args = new Object[] { constraintPropertyName, constraintOwningClass, propertyValue };
60-
if(!emailValidator.isValid(propertyValue.toString()) ) {
61+
String value = propertyValue.toString();
62+
if(StringUtils.isBlank(value))return;
63+
if(!emailValidator.isValid(value) ) {
6164
super.rejectValue(target,errors,ConstrainedProperty.DEFAULT_INVALID_EMAIL_MESSAGE_CODE,ConstrainedProperty.EMAIL_CONSTRAINT + ConstrainedProperty.INVALID_SUFFIX,args);
6265
}
6366
}

test/commons/org/codehaus/groovy/grails/validation/EmailConstraintTests.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public void testValidation() {
2424
2525
);
2626

27-
// must always pass for null value
28-
testConstraintPassed(
29-
getConstraint( "testString", Boolean.TRUE),
30-
null
31-
);
3227

3328
testConstraintDefaultMessage(
3429
getConstraint( "testString", Boolean.TRUE ),
@@ -38,6 +33,22 @@ public void testValidation() {
3833

3934
}
4035

36+
public void testNullValue() {
37+
// must always pass for null value
38+
testConstraintPassed(
39+
getConstraint( "testString", Boolean.TRUE),
40+
null
41+
);
42+
}
43+
44+
public void testBlankString() {
45+
// must always pass for blank value
46+
testConstraintPassed(
47+
getConstraint( "testString", Boolean.TRUE),
48+
""
49+
);
50+
}
51+
4152

4253
public void testCreation() {
4354
EmailConstraint constraint = new EmailConstraint();

0 commit comments

Comments
 (0)