[struts] 04/04: WW-5070 Fixes post cherry-pick issue
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5065-append-or-not-cherry-pick in repository https://gitbox.apache.org/repos/asf/struts.git commit d960e94820eaca17ae72d7d8e58a47fa1486072c Author: Lukasz Lenart AuthorDate: Mon Apr 27 20:38:25 2020 +0200 WW-5070 Fixes post cherry-pick issue --- .../com/opensymphony/xwork2/config/impl/ActionConfigMatcherTest.java | 1 + 1 file changed, 1 insertion(+) 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 aa2d648..ac52256 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;
[struts] 03/04: WW-5065 Adds missing flag value
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5065-append-or-not-cherry-pick in repository https://gitbox.apache.org/repos/asf/struts.git commit 3ff0ba78c171438a636d7f75c2b0a9271f932060 Author: Lukasz Lenart AuthorDate: Fri Apr 24 09:33:06 2020 +0200 WW-5065 Adds missing flag value --- core/src/main/java/org/apache/struts2/StrutsConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java index 6f71ce8..b48b8be 100644 --- a/core/src/main/java/org/apache/struts2/StrutsConstants.java +++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java @@ -348,5 +348,5 @@ public final class StrutsConstants { public static final String STRUTS_OGNL_AUTO_GROWTH_COLLECTION_LIMIT = "struts.ognl.autoGrowthCollectionLimit"; /** See {@link com.opensymphony.xwork2.config.impl.AbstractMatcher#appendNamedParameters */ -public static final String STRUTS_MATCHER_APPEND_NAMED_PARAMETERS = ""; +public static final String STRUTS_MATCHER_APPEND_NAMED_PARAMETERS = "struts.matcher.appendNamedParameters"; }
[struts] 02/04: WW-5065 Cleans up code and marks old constructor as deprecated
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5065-append-or-not-cherry-pick in repository https://gitbox.apache.org/repos/asf/struts.git commit 40c60da5a055f1d000d991abac64b3eb25a44c54 Author: Lukasz Lenart AuthorDate: Fri Apr 24 09:32:50 2020 +0200 WW-5065 Cleans up code and marks old constructor as deprecated --- .../xwork2/config/impl/AbstractMatcher.java| 36 +- 1 file changed, 21 insertions(+), 15 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 d170c03..7fe4254 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 @@ -40,11 +40,6 @@ public abstract class AbstractMatcher implements Serializable { private static final Logger LOG = LogManager.getLogger(AbstractMatcher.class); /** - * The logging instance - */ -private static final Logger log = LogManager.getLogger(AbstractMatcher.class); - -/** * Handles all wildcard pattern matching. */ PatternMatcher wildcard; @@ -73,6 +68,17 @@ public abstract class AbstractMatcher implements Serializable { } /** + * Creates a matcher with {@link #appendNamedParameters} set to true to keep backward compatibility + * + * @param helper an instance of {@link PatternMatcher} + * @deprecated use @{link {@link AbstractMatcher(PatternMatcher, boolean)} instead + */ +@Deprecated +public AbstractMatcher(PatternMatcher helper) { +this(helper, true); +} + +/** * * Finds and precompiles the wildcard patterns. Patterns will be evaluated * in the order they were added. Only patterns that actually contain a @@ -100,17 +106,17 @@ public abstract class AbstractMatcher implements Serializable { name = name.substring(1); } -log.debug("Compiling pattern '{}'", name); +LOG.debug("Compiling pattern '{}'", name); pattern = wildcard.compilePattern(name); -compiledPatterns.add(new Mapping(name, pattern, target)); +compiledPatterns.add(new Mapping<>(name, pattern, target)); if (looseMatch) { int lastStar = name.lastIndexOf('*'); if (lastStar > 1 && lastStar == name.length() - 1) { if (name.charAt(lastStar - 1) != '*') { pattern = wildcard.compilePattern(name.substring(0, lastStar - 1)); -compiledPatterns.add(new Mapping(name, pattern, target)); +compiledPatterns.add(new Mapping<>(name, pattern, target)); } } } @@ -131,12 +137,12 @@ public abstract class AbstractMatcher implements Serializable { E config = null; if (compiledPatterns.size() > 0) { -log.debug("Attempting to match '{}' to a wildcard pattern, {} available", potentialMatch, compiledPatterns.size()); +LOG.debug("Attempting to match '{}' to a wildcard pattern, {} available", potentialMatch, compiledPatterns.size()); -Map vars = new LinkedHashMap(); +Map vars = new LinkedHashMap<>(); for (Mapping m : compiledPatterns) { if (wildcard.match(vars, potentialMatch, m.getPattern())) { -log.debug("Value matches pattern '{}'", m.getOriginalPattern()); +LOG.debug("Value matches pattern '{}'", m.getOriginalPattern()); config = convert(potentialMatch, m.getTarget(), vars); break; } @@ -211,7 +217,7 @@ public abstract class AbstractMatcher implements Serializable { c = val.charAt(x); if (x < len - 2 && c == '{' && '}' == val.charAt(x+2)) { -varVal = (String)vars.get(String.valueOf(val.charAt(x + 1))); +varVal = vars.get(String.valueOf(val.charAt(x + 1))); if (varVal != null) { ret.append(varVal); } @@ -232,18 +238,18 @@ public abstract class AbstractMatcher implements Serializable { /** * The original pattern. */ -private String original; +private final String original; /** * The compiled pattern. */ -private Object pattern; +private final Object pattern; /** * The original object. */ -private E config; +private final E config; /** * Contructs a read-only Mapping instance.
[struts] 01/04: WW-5065 Defines a new flag to control appending params
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5065-append-or-not-cherry-pick in repository https://gitbox.apache.org/repos/asf/struts.git commit 9b9b3cd264f49ac51526a787a5db57c8c8e30efb Author: Lukasz Lenart AuthorDate: Wed Apr 22 07:59:13 2020 +0200 WW-5065 Defines a new flag to control appending params --- .../xwork2/config/impl/AbstractMatcher.java| 39 +--- .../xwork2/config/impl/ActionConfigMatcher.java| 28 - .../xwork2/config/impl/DefaultConfiguration.java | 17 +++-- .../xwork2/config/impl/NamespaceMatcher.java | 20 +- .../providers/XWorkConfigurationProvider.java | 2 + .../java/org/apache/struts2/StrutsConstants.java | 3 + .../config/impl/ActionConfigMatcherTest.java | 73 ++ 7 files changed, 164 insertions(+), 18 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..d170c03 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 @@ -36,6 +36,9 @@ import java.util.*; * @since 2.1 */ public abstract class AbstractMatcher implements Serializable { + +private static final Logger LOG = LogManager.getLogger(AbstractMatcher.class); + /** * The logging instance */ @@ -50,10 +53,23 @@ public abstract class AbstractMatcher implements Serializable { * The compiled patterns and their associated target objects */ List> compiledPatterns = new ArrayList<>(); -; + +/** + * This flag controls if passed named params should be appended + * to the map in {@link #replaceParameters(Map, Map)} + * and will be accessible in {@link com.opensymphony.xwork2.config.entities.ResultConfig}. + * If set to false, the named parameters won't be appended. + * + * This behaviour is controlled by {@link org.apache.struts2.StrutsConstants#STRUTS_MATCHER_APPEND_NAMED_PARAMETERS} + * + * @since 2.5.23 + * See WW-5065 + */ +private final boolean appendNamedParameters; -public AbstractMatcher(PatternMatcher helper) { +public AbstractMatcher(PatternMatcher helper, boolean appendNamedParameters) { this.wildcard = (PatternMatcher) helper; +this.appendNamedParameters = appendNamedParameters; } /** @@ -152,20 +168,23 @@ public abstract class AbstractMatcher implements Serializable { */ protected Map replaceParameters(Map orig, Map vars) { Map map = new LinkedHashMap<>(); - + //this will set the group index references, like {1} for (Map.Entry entry : orig.entrySet()) { 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()); + +if (appendNamedParameters) { +LOG.debug("Appending named parameters to the result map"); +//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/main/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcher.java b/core/src/main/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcher.java index b94fff6..344339e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcher.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/impl/ActionConfigMatcher.java @@ -58,7 +58,33 @@ public class ActionConfigMatcher extends AbstractMatcher implement public ActionConfigMatcher(PatternMatcher patternMatcher, Map configs, boolean looseMatch) { -super(patternMatcher); +this(patternMatcher, configs, looseMatch, true); +} + +/** + * Finds and precompiles the wildcard patterns from the ActionConfig + * "path" attributes. ActionConfig's will be evaluated in the order they + * exist in the config file. Only paths that actually contain a + * wildcard will be compiled. + * + * Patterns can optionally be matched "loosely". When + * the end of the pattern matches \*[^*]\*$ (wildcard, no wildcard, + * wildcard), if the pattern fails, it is also matched as if the + * last two charact
[struts] branch WW-5065-append-or-not-cherry-pick created (now d960e94)
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a change to branch WW-5065-append-or-not-cherry-pick in repository https://gitbox.apache.org/repos/asf/struts.git. at d960e94 WW-5070 Fixes post cherry-pick issue This branch includes the following new commits: new 9b9b3cd WW-5065 Defines a new flag to control appending params new 40c60da WW-5065 Cleans up code and marks old constructor as deprecated new 3ff0ba7 WW-5065 Adds missing flag value new d960e94 WW-5070 Fixes post cherry-pick issue The 4 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
[struts] branch WW-5065-append-or-not-cherry-pick updated: WW-5070 Drops unused import
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5065-append-or-not-cherry-pick in repository https://gitbox.apache.org/repos/asf/struts.git The following commit(s) were added to refs/heads/WW-5065-append-or-not-cherry-pick by this push: new 082d289 WW-5070 Drops unused import 082d289 is described below commit 082d289fa18b9261875c2d4e8a51743bdef9696b Author: Lukasz Lenart AuthorDate: Tue Apr 28 07:12:22 2020 +0200 WW-5070 Drops unused import --- .../opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java index ecd6d6e..63d8fab 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java @@ -107,7 +107,6 @@ import com.opensymphony.xwork2.validator.DefaultValidatorFactory; import com.opensymphony.xwork2.validator.DefaultValidatorFileParser; import com.opensymphony.xwork2.validator.ValidatorFactory; import com.opensymphony.xwork2.validator.ValidatorFileParser; -import com.sun.org.apache.xpath.internal.operations.Bool; import ognl.MethodAccessor; import ognl.PropertyAccessor; import org.apache.struts2.StrutsConstants;
[struts] branch WW-4043-moves-test-utils updated: WW-4043 Adds additional function to provide encoding
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-4043-moves-test-utils in repository https://gitbox.apache.org/repos/asf/struts.git The following commit(s) were added to refs/heads/WW-4043-moves-test-utils by this push: new 1e14438 WW-4043 Adds additional function to provide encoding 1e14438 is described below commit 1e1443871b4fc93f37cbf8347f980d3ee49b260c Author: Lukasz Lenart AuthorDate: Tue Apr 28 07:49:06 2020 +0200 WW-4043 Adds additional function to provide encoding --- .../main/java/org/apache/struts2/util/TestUtils.java | 18 +++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java b/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java index 131f009..2053813 100644 --- a/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java +++ b/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import java.net.URL; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,6 +32,7 @@ import java.util.regex.Pattern; * Utility methods for test classes */ public class TestUtils { + /** * A regex pattern for recognizing blocks of whitespace characters. */ @@ -83,9 +85,19 @@ public class TestUtils { } public static String readContent(URL url) throws Exception { -if (url == null) -throw new Exception("unable to verify a null URL"); +return readContent(url, StandardCharsets.UTF_8); +} + +public static String readContent(URL url, Charset encoding) throws Exception { +if (url == null) { +throw new IllegalArgumentException("Unable to verify a null URL"); +} -return IOUtils.toString(url.openStream(), StandardCharsets.UTF_8); +if (encoding == null) { +throw new IllegalArgumentException("Unable to verify the URL using a null Charset"); +} + +return IOUtils.toString(url.openStream(), encoding); } + }
[struts] 02/02: WW-4789 WW-3788 Cleans up code & JavaDocs formatting
This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch action-context-boost in repository https://gitbox.apache.org/repos/asf/struts.git commit 6c76275af69fa64067fc1bf5281bfd8e1eb210a5 Author: Lukasz Lenart AuthorDate: Tue Apr 28 08:14:45 2020 +0200 WW-4789 WW-3788 Cleans up code & JavaDocs formatting --- .../org/apache/struts2/result/PlainTextResult.java | 17 +-- .../struts2/result/ServletRedirectResult.java | 20 ++--- .../org/apache/struts2/result/StreamResult.java| 28 + .../org/apache/struts2/views/util/ContextUtil.java | 35 +++--- 4 files changed, 27 insertions(+), 73 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/result/PlainTextResult.java b/core/src/main/java/org/apache/struts2/result/PlainTextResult.java index c264817..7baaa05 100644 --- a/core/src/main/java/org/apache/struts2/result/PlainTextResult.java +++ b/core/src/main/java/org/apache/struts2/result/PlainTextResult.java @@ -31,15 +31,8 @@ import java.io.PrintWriter; import java.nio.charset.Charset; /** - * - * * A result that send the content out as plain text. Useful typically when needed * to display the raw content of a JSP or Html file for example. - * - * - * - * - * * * * location (default) = location of the file (jsp/html) to be displayed as plain text. @@ -47,26 +40,18 @@ import java.nio.charset.Charset; * response type (eg. Content-Type=text/plain; charset=UTF-8) and when reading * using a Reader. Some example of charSet would be UTF-8, ISO-8859-1 etc. * - * - * - * - * - * - * * + * ** * - * */myJspFile.jsp ** - * - * * */ public class PlainTextResult extends StrutsResultSupport { diff --git a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java index 0973492..9d7b461 100644 --- a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java +++ b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java @@ -46,8 +46,6 @@ import java.util.Map; import static javax.servlet.http.HttpServletResponse.SC_FOUND; /** - * - * * Calls the {@link HttpServletResponse#sendRedirect(String) sendRedirect} * method to the location specified. The response is told to redirect the * browser to the specified location (a new request from the client). The @@ -56,33 +54,19 @@ import static javax.servlet.http.HttpServletResponse.SC_FOUND; * available. This is because actions are built on a single-thread model. The * only way to pass data is through the session or with web parameters * (url?name=value) which can be OGNL expressions. - * - * - * + * * This result type takes the following parameters: - * - * * * - * * location (default) - the location to go to after execution. - * * parse - true by default. If set to false, the location param will * not be parsed for Ognl expressions. - * * anchor - Optional. Also known as "fragment" or colloquially as * "hash". You can specify an anchor for a result. * - * - * * This result follows the same rules from {@link StrutsResultSupport}. - * - * - * - * - * Example: - * * + * Example: * * ** /myJspFile.jsp * UTF-8 * *