craigmcc 2002/07/07 16:45:21
Modified: src/share/org/apache/struts/action ActionForward.java
src/share/org/apache/struts/config ForwardConfig.java
src/share/org/apache/struts/util RequestUtils.java
src/test/org/apache/struts/mock TestMockBase.java
src/test/org/apache/struts/util TestRequestUtils.java
Log:
Deal with a "path" attribute on a <forward> that does not contain a leading
slash by inserting one if necessary, for backwards compatibility.
PR: Bugzilla #10534
Submitted by: Matt Raible <matt at raibledesigns.com>
Revision Changes Path
1.8 +24 -4
jakarta-struts/src/share/org/apache/struts/action/ActionForward.java
Index: ActionForward.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForward.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ActionForward.java 2 Jul 2002 01:52:15 -0000 1.7
+++ ActionForward.java 7 Jul 2002 23:45:21 -0000 1.8
@@ -163,4 +163,24 @@
}
+ /**
+ * Construct a new instance with the specified values.
+ *
+ * @param name Name of this instance
+ * @param path Path for this instance
+ * @param redirect Redirect flag for this instance
+ * @param contextRelative Context relative flag for this instance
+ */
+ public ActionForward(String name, String path, boolean redirect,
+ boolean contextRelative) {
+
+ super();
+ setName(name);
+ setPath(path);
+ setRedirect(redirect);
+ setContextRelative(contextRelative);
+
+ }
+
+
}
1.6 +24 -4
jakarta-struts/src/share/org/apache/struts/config/ForwardConfig.java
Index: ForwardConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ForwardConfig.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ForwardConfig.java 4 Jul 2002 00:05:48 -0000 1.5
+++ ForwardConfig.java 7 Jul 2002 23:45:21 -0000 1.6
@@ -109,6 +109,26 @@
}
+ /**
+ * Construct a new instance with the specified values.
+ *
+ * @param name Name of this forward
+ * @param path Path to which control should be forwarded or redirected
+ * @param redirect Should we do a redirect?
+ * @param contextRelative Is this path context relative?
+ */
+ public ForwardConfig(String name, String path, boolean redirect,
+ boolean contextRelative) {
+
+ super();
+ setName(name);
+ setPath(path);
+ setRedirect(redirect);
+ setContextRelative(contextRelative);
+
+ }
+
+
// ----------------------------------------------------- Instance Variables
1.45 +18 -7
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- RequestUtils.java 5 Jul 2002 22:03:16 -0000 1.44
+++ RequestUtils.java 7 Jul 2002 23:45:21 -0000 1.45
@@ -1186,10 +1186,15 @@
public static String forwardURL(HttpServletRequest request,
ForwardConfig forward) {
+ String path = forward.getPath();
+
// Handle a ForwardConfig marked as context relative
StringBuffer sb = new StringBuffer();
if (forward.getContextRelative()) {
- sb.append(forward.getPath());
+ if (!path.startsWith("/")) {
+ sb.append("/");
+ }
+ sb.append(path);
return (sb.toString());
}
@@ -1201,7 +1206,10 @@
if (forwardPattern == null) {
// Performance optimization for previous default behavior
sb.append(appConfig.getPrefix());
- sb.append(forward.getPath());
+ if (!path.startsWith("/")) {
+ sb.append("/");
+ }
+ sb.append(path);
} else {
boolean dollar = false;
for (int i = 0; i < forwardPattern.length(); i++) {
@@ -1212,7 +1220,10 @@
sb.append(appConfig.getPrefix());
break;
case 'P':
- sb.append(forward.getPath());
+ if (!path.startsWith("/")) {
+ sb.append("/");
+ }
+ sb.append(path);
break;
case '$':
sb.append('$');
1.3 +22 -6 jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java
Index: TestMockBase.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestMockBase.java 2 Jul 2002 04:23:14 -0000 1.2
+++ TestMockBase.java 7 Jul 2002 23:45:21 -0000 1.3
@@ -162,7 +162,15 @@
// Forward "foo" to "/bar.jsp"
appConfig.addForwardConfig
- (new ActionForward("foo", "/bar.jsp", false));
+ (new ActionForward("foo", "/bar.jsp", false, false));
+
+ // Forward "relative1" to "relative.jsp" non-context-relative
+ appConfig.addForwardConfig
+ (new ActionForward("relative1", "relative.jsp", false, false));
+
+ // Forward "relative2" to "relative.jsp" context-relative
+ appConfig.addForwardConfig
+ (new ActionForward("relative2", "relative.jsp", false, true));
// Form Bean "static" is a standard ActionForm subclass
formBean = new ActionFormBean
@@ -220,7 +228,15 @@
// Forward "foo" to "/baz.jsp" (different from default)
appConfig2.addForwardConfig
- (new ActionForward("foo", "/baz.jsp", false));
+ (new ActionForward("foo", "/baz.jsp", false, false));
+
+ // Forward "relative1" to "relative.jsp" non-context-relative
+ appConfig2.addForwardConfig
+ (new ActionForward("relative1", "relative.jsp", false, false));
+
+ // Forward "relative2" to "relative.jsp" context-relative
+ appConfig2.addForwardConfig
+ (new ActionForward("relative2", "relative.jsp", false, true));
// Form Bean "static" is a standard ActionForm subclass (same as default)
formBean = new ActionFormBean
1.6 +86 -4
jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java
Index: TestRequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestRequestUtils.java 5 Jul 2002 22:03:16 -0000 1.5
+++ TestRequestUtils.java 7 Jul 2002 23:45:21 -0000 1.6
@@ -590,6 +590,46 @@
}
+ // Default subapp -- Forward with relative path (non-context-relative)
+ public void testComputeURL1f() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative1",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/relative.jsp",
+ url);
+ }
+
+
+ // Default subapp -- Forward with relative path (context-relative)
+ public void testComputeURL1g() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative2",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/relative.jsp",
+ url);
+ }
+
+
// Second subapp -- Forward only
public void testComputeURL2a() {
@@ -701,6 +741,48 @@
"/myapp/WEB-INF/pages/2/bar",
url);
+ }
+
+
+ // Second subapp -- Forward with relative path (non-context-relative)
+ public void testComputeURL2f() {
+
+ request.setAttribute(Action.APPLICATION_KEY, appConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative1",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/2/relative.jsp",
+ url);
+ }
+
+
+ // Second subapp -- Forward with relative path (context-relative)
+ public void testComputeURL2g() {
+
+ request.setAttribute(Action.APPLICATION_KEY, appConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative2",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/relative.jsp",
+ url);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>