Author: lukaszlenart
Date: Thu Jun 6 06:03:26 2013
New Revision: 1490165
URL: http://svn.apache.org/r1490165
Log:
WW-4095 WW-4094 Changes how pattern is compiled to be once per instance and
changes default regexp to match underscore
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java?rev=1490165&r1=1490164&r2=1490165&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
Thu Jun 6 06:03:26 2013
@@ -38,6 +38,7 @@ import org.apache.struts2.util.PrefixTri
import javax.servlet.http.HttpServletRequest;
import java.util.*;
+import java.util.regex.Pattern;
/**
* <!-- START SNIPPET: javadoc -->
@@ -170,7 +171,7 @@ public class DefaultActionMapper impleme
protected boolean allowSlashesInActionNames = false;
protected boolean alwaysSelectFullNamespace = false;
protected PrefixTrie prefixTrie = null;
- protected String allowedActionNames = "[a-z]*[A-Z]*[0-9]*[.\\-_!/]*";
+ protected Pattern allowedActionNames =
Pattern.compile("[a-zA-Z0-9._!/\\-]*");
protected List<String> extensions = new ArrayList<String>() {{
add("action");
@@ -262,7 +263,7 @@ public class DefaultActionMapper impleme
@Inject(value = StrutsConstants.STRUTS_ALLOWED_ACTION_NAMES, required =
false)
public void setAllowedActionNames(String allowedActionNames) {
- this.allowedActionNames = allowedActionNames;
+ this.allowedActionNames = Pattern.compile(allowedActionNames);
}
@Inject
@@ -432,15 +433,15 @@ public class DefaultActionMapper impleme
* @return safe action name
*/
protected String cleanupActionName(final String rawActionName) {
- if (rawActionName.matches(allowedActionNames)) {
+ if (allowedActionNames.matcher(rawActionName).matches()) {
return rawActionName;
} else {
if (LOG.isWarnEnabled()) {
- LOG.warn("Action [#0] do not match allowed action names
pattern [#1], cleaning it up!",
+ LOG.warn("Action [#0] does not match allowed action names
pattern [#1], cleaning it up!",
rawActionName, allowedActionNames);
}
String cleanActionName = rawActionName;
- for(String chunk : rawActionName.split(allowedActionNames)) {
+ for(String chunk : allowedActionNames.split(rawActionName)) {
cleanActionName = cleanActionName.replace(chunk, "");
}
if (LOG.isDebugEnabled()) {
Modified:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java?rev=1490165&r1=1490164&r2=1490165&view=diff
==============================================================================
---
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
(original)
+++
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
Thu Jun 6 06:03:26 2013
@@ -764,6 +764,12 @@ public class DefaultActionMapperTest ext
actionName = "test-action";
assertEquals("test-action", mapper.cleanupActionName(actionName));
+
+ actionName = "test_action";
+ assertEquals("test_action", mapper.cleanupActionName(actionName));
+
+ actionName = "test!bar.action";
+ assertEquals("test!bar.action", mapper.cleanupActionName(actionName));
}
}