From 907ce9802e43f63c2c548aa1f1ee6f41c980daa0 Mon Sep 17 00:00:00 2001 From: Lukasz Racon Date: Mon, 9 Nov 2015 14:14:07 -0600 Subject: [PATCH 1/2] Email validation blocks upper case letters Fix makes email validation regex case insensitive. --- core/src/main/resources/template/xhtml/form-close-validate.ftl | 2 +- .../com/opensymphony/xwork2/validator/EmailValidatorTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/template/xhtml/form-close-validate.ftl b/core/src/main/resources/template/xhtml/form-close-validate.ftl index f129156e5..1c8c629f0 100644 --- a/core/src/main/resources/template/xhtml/form-close-validate.ftl +++ b/core/src/main/resources/template/xhtml/form-close-validate.ftl @@ -114,7 +114,7 @@ END SNIPPET: supported-validators <#if validator.shortCircuit>continueValidation = false; } <#elseif validator.validatorType = "email"> - if (continueValidation && fieldValue != null && fieldValue.length > 0 && fieldValue.match("${validator.regex?js_string}")==null) { + if (continueValidation && fieldValue != null && fieldValue.length > 0 && fieldValue.match(new RegExp("${validator.regex?js_string}", "i"))==null) { addError(field, error); errors = true; <#if validator.shortCircuit>continueValidation = false; diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java index ca9a54990..d24d7955d 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java @@ -30,6 +30,7 @@ import com.opensymphony.xwork2.validator.validators.EmailValidator; public class EmailValidatorTest extends XWorkTestCase { public void testEmailValidity() throws Exception { + assertTrue(verifyEmailValidity("TmJee@Yahoo.com")); assertTrue(verifyEmailValidity("tmjee@yahoo.com")); assertTrue(verifyEmailValidityWithExpression("tmjee@yahoo.com", "\\b^[a-z]+@[a-z]+(\\.[a-z]+)*\\.com$\\b")); assertTrue(verifyEmailValidity("tm_jee@yahoo.co")); From fb896b6c1cc599c70954cea1ca2dac6c60b8961a Mon Sep 17 00:00:00 2001 From: Lukasz Racon Date: Thu, 12 Nov 2015 09:29:47 -0600 Subject: [PATCH 2/2] Switch to literal regexp notation, fix url validation --- .../src/main/resources/template/xhtml/form-close-validate.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/resources/template/xhtml/form-close-validate.ftl b/core/src/main/resources/template/xhtml/form-close-validate.ftl index 1c8c629f0..e8dd9915a 100644 --- a/core/src/main/resources/template/xhtml/form-close-validate.ftl +++ b/core/src/main/resources/template/xhtml/form-close-validate.ftl @@ -114,13 +114,13 @@ END SNIPPET: supported-validators <#if validator.shortCircuit>continueValidation = false; } <#elseif validator.validatorType = "email"> - if (continueValidation && fieldValue != null && fieldValue.length > 0 && fieldValue.match(new RegExp("${validator.regex?js_string}", "i"))==null) { + if (continueValidation && fieldValue != null && fieldValue.length > 0 && fieldValue.match(/${validator.regex}/i)==null) { addError(field, error); errors = true; <#if validator.shortCircuit>continueValidation = false; } <#elseif validator.validatorType = "url"> - if (continueValidation && fieldValue != null && fieldValue.length > 0 && fieldValue.match("/${validator.urlRegex?js_string}/i")==null) { + if (continueValidation && fieldValue != null && fieldValue.length > 0 && fieldValue.match(/${validator.urlRegex}/i)==null) { addError(field, error); errors = true; <#if validator.shortCircuit>continueValidation = false;