Author: markt
Date: Tue Feb 10 23:36:37 2015
New Revision: 1658840
URL: http://svn.apache.org/r1658840
Log:
Follow-up to r1658804 (kkolinko review)
Handle case where canonical path ends in File.separator
Modified:
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/StandardContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1658840&r1=1658839&r2=1658840&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Feb 10
23:36:37 2015
@@ -4408,10 +4408,13 @@ public class StandardContext extends Con
if (resources != null) {
try {
WebResource resource = resources.getResource(path);
- if (resource.isDirectory()) {
- return resource.getCanonicalPath() + File.separatorChar;
+ String canonicalPath = resource.getCanonicalPath();
+ if (canonicalPath == null) {
+ return null;
+ } else if (resource.isDirectory() &&
!canonicalPath.endsWith(File.separator)) {
+ return canonicalPath + File.separatorChar;
} else {
- return resource.getCanonicalPath();
+ return canonicalPath;
}
} catch (IllegalArgumentException iae) {
// ServletContext.getRealPath() does not allow this to be
thrown
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=1658840&r1=1658839&r2=1658840&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
(original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java Tue Feb
10 23:36:37 2015
@@ -55,6 +55,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.apache.catalina.Context;
+import org.apache.catalina.Host;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleException;
@@ -942,25 +943,47 @@ public class TestStandardContext extends
* with previous major versions.
*/
@Test
- public void testBug57556() throws Exception {
+ public void testBug57556a() throws Exception {
Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);
Context testContext = ((Context) tomcat.getHost().findChildren()[0]);
- doTestBug57556(testContext, "/", true);
- doTestBug57556(testContext, "/jsp", true);
- doTestBug57556(testContext, "/jsp/", true);
- doTestBug57556(testContext, "/index.html", false);
+
+ File f = new File(testContext.getDocBase());
+ if (!f.isAbsolute()) {
+ f = new File(((Host) testContext.getParent()).getAppBaseFile(),
f.getPath());
+ }
+ String base = f.getCanonicalPath();
+
+
+ doTestBug57556(testContext, "", base + File.separatorChar);
+ doTestBug57556(testContext, "/", base + File.separatorChar);
+ doTestBug57556(testContext, "/jsp", base + File.separatorChar+ "jsp" +
File.separatorChar);
+ doTestBug57556(testContext, "/jsp/", base + File.separatorChar+ "jsp"
+ File.separatorChar);
+ doTestBug57556(testContext, "/index.html", base + File.separatorChar +
"index.html");
// Doesn't exist so Tomcat will assume it is a file, not a directory.
- doTestBug57556(testContext, "/foo", false);
+ doTestBug57556(testContext, "/foo", base + File.separatorChar + "foo");
}
- private void doTestBug57556(Context testContext, String path, boolean
endsInSeparator) throws Exception {
+ @Test
+ public void testBug57556b() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+ File docBase = new File("/");
+ Context testContext = tomcat.addContext("", docBase.getAbsolutePath());
+ tomcat.start();
+
+ File f = new File(testContext.getDocBase());
+ if (!f.isAbsolute()) {
+ f = new File(((Host) testContext.getParent()).getAppBaseFile(),
f.getPath());
+ }
+ String base = f.getCanonicalPath();
+
+ doTestBug57556(testContext, "", base);
+ doTestBug57556(testContext, "/", base);
+ }
+
+ private void doTestBug57556(Context testContext, String path, String
expected) throws Exception {
String realPath = testContext.getRealPath(path);
Assert.assertNotNull(realPath);
- if (endsInSeparator) {
- Assert.assertTrue(realPath, realPath.endsWith(File.separator));
- } else {
- Assert.assertFalse(realPath, realPath.endsWith(File.separator));
- }
+ Assert.assertEquals(expected, realPath);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]