mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4671 makes URLValidator case insensitive
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user