mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
Fix handling of empty extension during url creation
WW-2163 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@573805 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -137,6 +137,13 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location it was created with, mainly for testing
|
||||
*/
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last parsed and encoded location value
|
||||
|
||||
@@ -228,7 +228,7 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
ServletRedirectResult redirect = new ServletRedirectResult();
|
||||
container.inject(redirect);
|
||||
String extension = getDefaultExtension();
|
||||
if (extension != null) {
|
||||
if (extension != null && extension.length() > 0) {
|
||||
location += "." + extension;
|
||||
}
|
||||
redirect.setLocation(location);
|
||||
@@ -499,8 +499,11 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
|
||||
String extension = getDefaultExtension();
|
||||
if (extension != null) {
|
||||
if (uri.indexOf('.' + extension) == -1) {
|
||||
uri.append(".").append(extension);
|
||||
|
||||
if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.' + extension) == -1)) {
|
||||
if (extension.length() > 0) {
|
||||
uri.append(".").append(extension);
|
||||
}
|
||||
if (params.length() > 0) {
|
||||
uri.append(params);
|
||||
}
|
||||
|
||||
+39
-1
@@ -27,6 +27,7 @@ import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.dispatcher.ServletRedirectResult;
|
||||
import org.apache.struts2.dispatcher.StrutsResultSupport;
|
||||
import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
|
||||
import org.apache.struts2.views.jsp.StrutsMockHttpServletResponse;
|
||||
|
||||
@@ -376,9 +377,34 @@ public class DefaultActionMapperTest extends StrutsTestCase {
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
|
||||
Result result = actionMapping.getResult();
|
||||
StrutsResultSupport result = (StrutsResultSupport) actionMapping.getResult();
|
||||
assertNotNull(result);
|
||||
assertTrue(result instanceof ServletRedirectResult);
|
||||
|
||||
assertEquals("myAction.action", result.getLocation());
|
||||
|
||||
// TODO: need to test location but there's noaccess to the property/method, unless we use reflection
|
||||
}
|
||||
|
||||
public void testRedirectActionPrefixWithEmptyExtension() throws Exception {
|
||||
Map parameterMap = new HashMap();
|
||||
parameterMap.put(DefaultActionMapper.REDIRECT_ACTION_PREFIX + "myAction", "");
|
||||
|
||||
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
|
||||
request.setupGetServletPath("/someServletPath");
|
||||
request.setParameterMap(parameterMap);
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.setContainer(container);
|
||||
defaultActionMapper.setExtensions(",,");
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
|
||||
StrutsResultSupport result = (StrutsResultSupport) actionMapping.getResult();
|
||||
assertNotNull(result);
|
||||
assertTrue(result instanceof ServletRedirectResult);
|
||||
|
||||
assertEquals("myAction", result.getLocation());
|
||||
|
||||
// TODO: need to test location but there's noaccess to the property/method, unless we use reflection
|
||||
}
|
||||
@@ -551,5 +577,17 @@ public class DefaultActionMapperTest extends StrutsTestCase {
|
||||
|
||||
assertEquals("/myActionName.action", uri);
|
||||
}
|
||||
|
||||
public void testGetUriFromActionMapperWhenBlankExtension() throws Exception {
|
||||
DefaultActionMapper mapper = new DefaultActionMapper();
|
||||
mapper.setExtensions(",,");
|
||||
ActionMapping actionMapping = new ActionMapping();
|
||||
actionMapping.setMethod("myMethod");
|
||||
actionMapping.setName("myActionName");
|
||||
actionMapping.setNamespace("/myNamespace");
|
||||
String uri = mapper.getUriFromActionMapping(actionMapping);
|
||||
|
||||
assertEquals("/myNamespace/myActionName!myMethod", uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user