This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch struts-2-5-x in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/struts-2-5-x by this push: new ec56290 Removing unnecessary part of AbstractMatcher#replaceParameters method and adding a test to make sure it is working correctly new 5c82f02 Merge pull request #400 from atkaiser/WW5065-FixAbstractMatcherReplaceParams ec56290 is described below commit ec56290056038b240e3cf9f1fa40281b9d968b08 Author: Alex Kaiser <alextkai...@gmail.com> AuthorDate: Wed Apr 8 11:23:02 2020 -0700 Removing unnecessary part of AbstractMatcher#replaceParameters method and adding a test to make sure it is working correctly --- .../xwork2/config/impl/AbstractMatcher.java | 8 ----- .../config/impl/ActionConfigMatcherTest.java | 41 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) 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 3b3b74b..eee29ec 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<E> 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<String,String> 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 7e0a60c..3fba5b1 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<String, ActionConfig> map = new HashMap<>(); + + HashMap<String, String> 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<String,ActionConfig> buildActionConfigMap() { Map<String, ActionConfig> map = new HashMap<>();