You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2014/11/18 15:40:49 UTC

svn commit: r1640351 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/core/LocalStrings.properties java/org/apache/catalina/core/StandardContext.java test/org/apache/catalina/core/TestStandardContext.java webapps/docs/changelog.xml

Author: kkolinko
Date: Tue Nov 18 14:40:48 2014
New Revision: 1640351

URL: http://svn.apache.org/r1640351
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57216
Improve handling of invalid context paths.
This adds handling of paths that end with '/', including "/".
This corrects handling of null path that will no result in "" instead of "/null".

Merged r1640089 r1640276 r1640349 from tomcat/tc8.0.x/trunk.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1640088,1640275,1640347
  Merged /tomcat/tc8.0.x/trunk:r1640089,1640276,1640349

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1640351&r1=1640350&r2=1640351&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties Tue Nov 18 14:40:48 2014
@@ -155,7 +155,7 @@ standardContext.notStarted=Context with 
 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.pathInvalid=A context path must either be an empty string or start with a ''/'' and do not end with a ''/''. The path [{0}] does not meet these criteria and has been changed to [{1}]
 standardContext.postconstruct.duplicate=Duplicate post construct method definition for class {0}
 standardContext.postconstruct.required=Both fully qualified class name and method name are required
 standardContext.predestroy.duplicate=Duplicate pre destroy method definition for class {0}

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1640351&r1=1640350&r2=1640351&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/StandardContext.java Tue Nov 18 14:40:48 2014
@@ -2163,12 +2163,23 @@ public class StandardContext extends Con
      */
     @Override
     public void setPath(String path) {
-        if (path == null || (!path.equals("") && !path.startsWith("/"))) {
+        boolean invalid = false;
+        if (path == null || path.equals("/")) {
+            invalid = true;
+            this.path = "";
+        } else if ("".equals(path) || path.startsWith("/")) {
+            this.path = path;
+        } else {
+            invalid = true;
             this.path = "/" + path;
+        }
+        if (this.path.endsWith("/")) {
+            invalid = true;
+            this.path = this.path.substring(0, this.path.length() - 1);
+        }
+        if (invalid) {
             log.warn(sm.getString(
                     "standardContext.pathInvalid", path, this.path));
-        } else {
-            this.path = path;
         }
         encodedPath = urlEncoder.encode(this.path);
         if (getName() == null) {

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java?rev=1640351&r1=1640350&r2=1640351&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java Tue Nov 18 14:40:48 2014
@@ -872,4 +872,22 @@ public class TestStandardContext extends
         Assert.assertThat(Arrays.asList(context.getResourceOnlyServlets().split(",")),
                 CoreMatchers.hasItems("a", "b", "c"));
     }
+
+    @Test
+    public void testSetPath() {
+        testSetPath("", "");
+        testSetPath("/foo", "/foo");
+        testSetPath("/foo/bar", "/foo/bar");
+        testSetPath(null, "");
+        testSetPath("/", "");
+        testSetPath("foo", "/foo");
+        testSetPath("/foo/bar/", "/foo/bar");
+        testSetPath("foo/bar/", "/foo/bar");
+    }
+
+    private void testSetPath(String value, String expectedValue) {
+        StandardContext context = new StandardContext();
+        context.setPath(value);
+        Assert.assertEquals(expectedValue, context.getPath());
+    }
 }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1640351&r1=1640350&r2=1640351&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Nov 18 14:40:48 2014
@@ -63,6 +63,15 @@
         in a directory context for a user with specified user name. Based on
         a patch provided by Jason McIntosh. (violetagg)
       </fix>
+      <fix>
+        <bug>57216</bug>: Improve handling of invalid context paths. A context
+        path should either be an empty string or start with a
+        <code>&apos;/&apos;</code> and do not end with a
+        <code>&apos;/&apos;</code>. Invalid context path are automatically
+        corrected and a warning is logged. The <code>null</code> and
+        <code>&quot;/&quot;</code> values are now correctly changed to
+        <code>&quot;&quot;</code>. (markt/kkolinko)
+      </fix>
     </changelog>
   </subsection>
 </section>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org