Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=42673
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 9 Nov 2008 01:35:58 +0000 (01:35 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 9 Nov 2008 01:35:58 +0000 (01:35 +0000)
Correctly handle includes with multi-level contexts
Patch provided by Peter Jodeleit

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@712461 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/ssi/SSIServletExternalResolver.java

index fe7dd2a..721a846 100644 (file)
@@ -353,14 +353,12 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
     }
 
 
-    protected String getPathWithoutContext(String servletPath) {
-        String retVal = null;
-        int secondSlash = servletPath.indexOf('/', 1);
-        if (secondSlash >= 0) {
-            //cut off context
-            retVal = servletPath.substring(secondSlash);
+    protected String getPathWithoutContext(final String contextPath,
+            final String servletPath) {
+        if (servletPath.startsWith(contextPath)) {
+            return servletPath.substring(contextPath.length());
         }
-        return retVal;
+        return servletPath;
     }
 
 
@@ -419,7 +417,8 @@ public class SSIServletExternalResolver implements SSIExternalResolver {
                 // ie:
                 // '/file1.shtml' vs '/appName1/file1.shtml'
                 if (!isRootContext(normContext)) {
-                    String noContext = getPathWithoutContext(normalized);
+                    String noContext = getPathWithoutContext(
+                            normContext.getContextPath(), normalized);
                     if (noContext == null) {
                         throw new IOException(
                                 "Couldn't remove context from path: "