diff --git a/core/src/main/java/com/opensymphony/xwork2/config/impl/AbstractMatcher.java b/core/src/main/java/com/opensymphony/xwork2/config/impl/AbstractMatcher.java index 3b3b74b90..eee29ec13 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/impl/AbstractMatcher.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/impl/AbstractMatcher.java @@ -158,14 +158,6 @@ public abstract class AbstractMatcher implements Serializable { map.put(entry.getKey(), convertParam(entry.getValue(), vars)); } - //the values map will contain entries like name->"Lex Luthor" and 1->"Lex Luthor" - //now add the non-numeric values - for (Map.Entry entry: vars.entrySet()) { - if (!NumberUtils.isCreatable(entry.getKey())) { - map.put(entry.getKey(), entry.getValue()); - } - } - return map; } diff --git a/core/src/test/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcherTest.java b/core/src/test/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcherTest.java index 7e0a60c7a..3fba5b13c 100644 --- a/core/src/test/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcherTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcherTest.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig; import com.opensymphony.xwork2.config.entities.InterceptorMapping; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.util.WildcardHelper; +import org.apache.struts2.util.RegexPatternMatcher; import java.util.HashMap; import java.util.Map; @@ -142,6 +143,46 @@ public class ActionConfigMatcherTest extends XWorkTestCase { } + /** + * Test to make sure the {@link AbstractMatcher#replaceParameters(Map, Map)} method isn't adding values to the + * return value. + */ + public void testReplaceParameters() { + Map map = new HashMap<>(); + + HashMap params = new HashMap<>(); + params.put("first", "{1}"); + + ActionConfig config = new ActionConfig.Builder("package", "foo/{one}/{two}/{three}", "foo.bar.Action") + .addParams(params) + .addExceptionMapping(new ExceptionMappingConfig.Builder("foo{1}", "java.lang.{2}Exception", "success{1}") + .addParams(new HashMap<>(params)) + .build()) + .addResultConfig(new ResultConfig.Builder("success{1}", "foo.{2}").addParams(params).build()) + .setStrictMethodInvocation(false) + .build(); + map.put("foo/{one}/{two}/{three}", config); + ActionConfigMatcher replaceMatcher = new ActionConfigMatcher(new RegexPatternMatcher(), map, false); + ActionConfig matched = replaceMatcher.match("foo/paramOne/paramTwo/paramThree"); + assertNotNull("ActionConfig should be matched", matched); + + // Verify all The ActionConfig, ExceptionConfig, and ResultConfig have the correct number of params + assertTrue("The ActionConfig should have the correct number of params", + matched.getParams().size() == 1); + assertTrue("The ExceptionMappingConfigs should have the correct number of params", + matched.getExceptionMappings().get(0).getParams().size() == 1); + assertTrue("The ResultConfigs should have the correct number of params", + matched.getResults().get("successparamOne").getParams().size() == 1); + + // Verify the params are still getting their values replaced correctly + assertTrue("The ActionConfig params have replaced values", + "paramOne".equals(matched.getParams().get("first"))); + assertTrue("The ActionConfig params have replaced values", + "paramOne".equals(matched.getExceptionMappings().get(0).getParams().get("first"))); + assertTrue("The ActionConfig params have replaced values", + "paramOne".equals(matched.getResults().get("successparamOne").getParams().get("first"))); + } + private Map buildActionConfigMap() { Map map = new HashMap<>();