From 27181d4106e426838e1d2994f8251f010c4f02b7 Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 11 Mar 2011 18:30:14 +0000 Subject: [PATCH] Better handling for invalid context paths in server.xml git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1080714 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/core/LocalStrings.properties | 1 + java/org/apache/catalina/core/StandardContext.java | 12 +++++++++--- webapps/docs/changelog.xml | 9 +++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/core/LocalStrings.properties b/java/org/apache/catalina/core/LocalStrings.properties index 97d728be9..39e8cabae 100644 --- a/java/org/apache/catalina/core/LocalStrings.properties +++ b/java/org/apache/catalina/core/LocalStrings.properties @@ -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 diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index a6bcc0441..ab00d8afa 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -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); } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6be8b9281..9d0e4264f 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -43,6 +43,15 @@ Other -->
+ + + + Automatically correct invalid paths when specified for Context elements + inside server.xml and log a warning that the configuration has been + corrected. (markt) + + + -- 2.11.0