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:04:08 UTC
svn commit: r1640347 - in /tomcat/trunk:
java/org/apache/catalina/core/LocalStrings.properties
java/org/apache/catalina/core/StandardContext.java
test/org/apache/catalina/core/TestStandardContext.java
Author: kkolinko
Date: Tue Nov 18 14:04:07 2014
New Revision: 1640347
URL: http://svn.apache.org/r1640347
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57216
Warn and correct invalid context paths that end with a '/'
Modified:
tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1640347&r1=1640346&r2=1640347&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Tue Nov 18 14:04:07 2014
@@ -131,7 +131,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/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1640347&r1=1640346&r2=1640347&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Nov 18 14:04:07 2014
@@ -2010,13 +2010,17 @@ public class StandardContext extends Con
public void setPath(String path) {
boolean invalid = false;
if (path == null || path.equals("/")) {
+ invalid = true;
this.path = "";
+ } else if ("".equals(path) || path.startsWith("/")) {
+ this.path = path;
+ } else {
invalid = true;
- } else if (!path.equals("") && !path.startsWith("/")) {
this.path = "/" + path;
+ }
+ if (this.path.endsWith("/")) {
invalid = true;
- } else {
- this.path = path;
+ this.path = this.path.substring(0, this.path.length() - 1);
}
if (invalid) {
log.warn(sm.getString(
Modified: tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java?rev=1640347&r1=1640346&r2=1640347&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java Tue Nov 18 14:04:07 2014
@@ -944,4 +944,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());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org