You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2020/09/17 11:19:38 UTC
[struts] branch master updated: WW-5087 handle Parameter.Empty
properly
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/master by this push:
new 88a54d1 WW-5087 handle Parameter.Empty properly
new 3528edf Merge pull request #439 from yasserzamani/WW-5087master
88a54d1 is described below
commit 88a54d1fb084625228c046a91679dc8eabfa233a
Author: Yasser Zamani <ya...@apache.org>
AuthorDate: Mon Sep 14 18:00:54 2020 +0430
WW-5087 handle Parameter.Empty properly
There was a bug with AliasInterceptor not handling the Parameter.Empty that is returned from HttpParameters.get(). Since HttpParameters.get() always returns a non-null value, the Evaluated object is treated as always being defined, which results in the empty value being set incorrectly on the stack.
---
.../xwork2/interceptor/AliasInterceptor.java | 6 +++++-
.../xwork2/interceptor/AliasInterceptorTest.java | 24 ++++++++++++++++++++++
core/src/test/resources/xwork-sample.xml | 2 +-
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java
index 992bf94..3a41df7 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/AliasInterceptor.java
@@ -31,6 +31,7 @@ import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.dispatcher.HttpParameters;
+import org.apache.struts2.dispatcher.Parameter;
import org.apache.struts2.StrutsConstants;
import java.util.Map;
@@ -173,7 +174,10 @@ public class AliasInterceptor extends AbstractInterceptor {
HttpParameters contextParameters = ActionContext.getContext().getParameters();
if (null != contextParameters) {
- value = new Evaluated(contextParameters.get(name));
+ Parameter param = contextParameters.get(name);
+ if (param.isDefined()) {
+ value = new Evaluated(param.getValue());
+ }
}
}
if (value.isDefined()) {
diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/AliasInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/AliasInterceptorTest.java
index 6c0480d..9014125 100644
--- a/core/src/test/java/com/opensymphony/xwork2/interceptor/AliasInterceptorTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/AliasInterceptorTest.java
@@ -23,6 +23,7 @@ import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import com.opensymphony.xwork2.mock.MockActionProxy;
+import org.apache.struts2.dispatcher.HttpParameters;
import java.util.HashMap;
import java.util.Map;
@@ -60,7 +61,30 @@ public class AliasInterceptorTest extends XWorkTestCase {
actionOne.setFoo(17);
actionOne.setBar(23);
proxy.execute();
+ assertEquals("name to be copied", actionOne.getAliasSource());
assertEquals(actionOne.getAliasSource(), actionOne.getAliasDest());
+ assertNull(actionOne.getBlah()); // WW-5087
+ }
+
+ public void testNotExisting() throws Exception {
+ Map<String, Object> params = new HashMap<>();
+ Map<String, Object> httpParams = new HashMap<>();
+ httpParams.put("notExisting", "from http parameter");
+ params.put(ActionContext.PARAMETERS, HttpParameters.create(httpParams).build());
+
+ XmlConfigurationProvider provider = new XmlConfigurationProvider("xwork-sample.xml");
+ container.inject(provider);
+ loadConfigurationProviders(provider);
+ ActionProxy proxy = actionProxyFactory.createActionProxy("", "aliasTest", null, params);
+ SimpleAction actionOne = (SimpleAction) proxy.getAction();
+
+ // prevent ERROR result
+ actionOne.setFoo(-1);
+ actionOne.setBar(1);
+
+ proxy.execute();
+ assertEquals("from http parameter", actionOne.getBlah());
+ assertNull(actionOne.getAliasDest()); // WW-5087
}
public void testInvalidAliasExpression() throws Exception {
diff --git a/core/src/test/resources/xwork-sample.xml b/core/src/test/resources/xwork-sample.xml
index 875c4e5..5ff1e39 100644
--- a/core/src/test/resources/xwork-sample.xml
+++ b/core/src/test/resources/xwork-sample.xml
@@ -97,7 +97,7 @@
</action>
<action name="aliasTest" class="com.opensymphony.xwork2.SimpleAction">
- <param name="aliases">#{ "aliasSource" : "aliasDest", "bar":"baz" }</param>
+ <param name="aliases">#{ "aliasSource" : "aliasDest", "bar":"baz", "notExisting":"blah" }</param>
<interceptor-ref name="params"/>
<interceptor-ref name="alias"/>
<result name="success" type="mock" />