vmassol 01/07/05 07:24:45
Modified: cactus/src/framework/servlet23/org/apache/commons/cactus/server
HttpServletRequestWrapper.java
Log:
changed implementation of HttpServletRequestWrapper.getRequestDispatcher() for
Servlet API 2.3
Revision Changes Path
1.4 +41 -1
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/HttpServletRequestWrapper.java
Index: HttpServletRequestWrapper.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/HttpServletRequestWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HttpServletRequestWrapper.java 2001/07/04 09:17:30 1.3
+++ HttpServletRequestWrapper.java 2001/07/05 14:24:45 1.4
@@ -414,8 +414,18 @@
} else {
- fullPath = getServletPath() + "/../" + thePath;
+ String pI = getPathInfo();
+ if (pI == null) {
+ fullPath = catPath(getServletPath(), thePath);
+ } else {
+ fullPath = catPath(getServletPath() + pI, thePath);
+ }
+ if (fullPath == null) {
+ m_Logger.exit("getRequestDispatcher");
+ return null;
+ }
+
}
m_Logger.debug("Computed full path : [" + fullPath + "]");
@@ -425,6 +435,36 @@
m_Logger.exit("getRequestDispatcher");
return dispatcher;
+ }
+
+ /**
+ * Will concatenate 2 paths, dealing with ..
+ * ( /a/b/c + d = /a/b/d, /a/b/c + ../d = /a/d ). Code borrowed from
+ * Tomcat 3.2.2 !
+ *
+ * @return null if error occurs
+ */
+ private String catPath(String lookupPath, String path)
+ {
+ // Cut off the last slash and everything beyond
+ int index = lookupPath.lastIndexOf("/");
+ lookupPath = lookupPath.substring(0, index);
+
+ // Deal with .. by chopping dirs off the lookup path
+ while (path.startsWith("../")) {
+ if (lookupPath.length() > 0) {
+ index = lookupPath.lastIndexOf("/");
+ lookupPath = lookupPath.substring(0, index);
+ } else {
+ // More ..'s than dirs, return null
+ return null;
+ }
+
+ index = path.indexOf("../") + 3;
+ path = path.substring(index);
+ }
+
+ return lookupPath + "/" + path;
}
public String getRemoteHost()