struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject struts git commit: WW-4671 makes URLValidator case insensitive
Date Thu, 28 Jul 2016 11:09:37 GMT
Repository: struts
Updated Branches:
  refs/heads/master 0bd2e7058 -> d19b9eaa8


WW-4671 makes URLValidator case insensitive


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/d19b9eaa
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/d19b9eaa
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/d19b9eaa

Branch: refs/heads/master
Commit: d19b9eaa82753a5dd671ee4f0847574f65f4aebf
Parents: 0bd2e70
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Thu Jul 28 13:09:21 2016 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Thu Jul 28 13:09:21 2016 +0200

----------------------------------------------------------------------
 .../validator/validators/URLValidator.java      |  2 +-
 .../xwork2/validator/URLValidatorTest.java      | 42 ++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/d19b9eaa/core/src/main/java/com/opensymphony/xwork2/validator/validators/URLValidator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/validators/URLValidator.java
b/core/src/main/java/com/opensymphony/xwork2/validator/validators/URLValidator.java
index fd678a7..735d861 100644
--- a/core/src/main/java/com/opensymphony/xwork2/validator/validators/URLValidator.java
+++ b/core/src/main/java/com/opensymphony/xwork2/validator/validators/URLValidator.java
@@ -55,7 +55,7 @@ public class URLValidator extends FieldValidatorSupport {
             return;
         }
 
-        if (!(value.getClass().equals(String.class)) || !Pattern.compile(getUrlRegex()).matcher((String)
value).matches()) {
+        if (!(value.getClass().equals(String.class)) || !Pattern.compile(getUrlRegex(), Pattern.CASE_INSENSITIVE).matcher(String.valueOf(value)).matches())
{
             addFieldError(fieldName, object);
         }
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/d19b9eaa/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java
index 77223eb..56a9bcc 100644
--- a/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java
@@ -20,6 +20,8 @@ import com.opensymphony.xwork2.XWorkTestCase;
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.validator.validators.URLValidator;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.regex.Pattern;
 
 /**
@@ -146,6 +148,46 @@ public class URLValidatorTest extends XWorkTestCase {
         assertTrue(pattern.matcher("http://localhost:8080/myapp").matches());
     }
 
+	public void testValidUrlCaseInsesitive() throws Exception {
+		// given
+		final Map<String, Object> fieldErrors = new HashMap<>();
+
+		URLValidator validator = new URLValidator() {
+			@Override
+			public String getFieldName() {
+				return "url";
+			}
+
+			@Override
+			protected Object getFieldValue(String name, Object object) throws ValidationException
{
+				return object;
+			}
+
+			@Override
+			protected void addFieldError(String propertyName, Object object) {
+				fieldErrors.put(propertyName, object);
+			}
+		};
+
+		// when
+        validator.validate("http://localhost:8080/myapp");
+
+		// then
+		assertTrue(fieldErrors.isEmpty());
+
+		// when
+        validator.validate("http://LOCALHOST:8080/MYAPP");
+
+		// then
+		assertTrue(fieldErrors.isEmpty());
+
+		// when
+        validator.validate("http://www.appache.org/TEST");
+
+		// then
+		assertTrue(fieldErrors.isEmpty());
+    }
+
 	@Override
     protected void setUp() throws Exception {
 	    super.setUp();


Mime
View raw message