mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
Merge pull request #438 from yasserzamani/WW-5087
WW-5087 handle Parameter.Empty properly
This commit is contained in:
@@ -32,6 +32,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 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()) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user