Better handling for invalid context paths in server.xml
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 11 Mar 2011 18:30:14 +0000 (18:30 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 11 Mar 2011 18:30:14 +0000 (18:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1080714 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/LocalStrings.properties
java/org/apache/catalina/core/StandardContext.java
webapps/docs/changelog.xml

index 97d728b..39e8cab 100644 (file)
@@ -130,6 +130,7 @@ standardContext.notStarted=Context with name [{0}] has not yet been started
 standardContext.notWrapper=Child of a Context must be a Wrapper
 standardContext.parameter.duplicate=Duplicate context initialization parameter {0}
 standardContext.parameter.required=Both parameter name and parameter value are required
+standardContext.pathInvalid=A context path must either be an empty string or start with a ''/''. The path [{0}] does not meet these criteria and has been changed to [{1}] 
 standardContext.reloadingCompleted=Reloading Context with name [{0}] is completed
 standardContext.reloadingFailed=Reloading this Context failed due to previous errors
 standardContext.reloadingStarted=Reloading Context with name [{0}] has started
index a6bcc04..ab00d8a 100644 (file)
@@ -2040,10 +2040,16 @@ public class StandardContext extends ContainerBase
      */
     @Override
     public void setPath(String path) {
-        this.path = path;
-        encodedPath = urlEncoder.encode(path);
+        if (path == null || (!path.equals("") && !path.startsWith("/"))) {
+            this.path = "/" + path;
+            log.warn(sm.getString(
+                    "standardContext.pathInvalid", path, this.path));
+        } else {
+            this.path = path;
+        }
+        encodedPath = urlEncoder.encode(this.path);
         if (getName() == null) {
-            setName(path);
+            setName(this.path);
         }
     }
 
index 6be8b92..9d0e426 100644 (file)
   Other
 -->
 <section name="Tomcat 7.0.12 (markt)">
+  <subsection name="Catalina">
+    <changelog>
+      <add>
+        Automatically correct invalid paths when specified for Context elements
+        inside server.xml and log a warning that the configuration has been
+        corrected. (markt)
+      </add>
+    </changelog>
+  </subsection>
   <subsection name="Other">
     <changelog>
       <update>