Author: markt
Date: Tue Feb 10 20:54:07 2015
New Revision: 1658804
URL: http://svn.apache.org/r1658804
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57556
Align getRealPath() behaviour with that of earlier versions and include a
trailing separator if the real path refers to a directory.
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=1658804&r1=1658803&r2=1658804&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Feb 10
20:54:07 2015
@@ -4407,7 +4407,12 @@ public class StandardContext extends Con
}
if (resources != null) {
try {
- return resources.getResource(path).getCanonicalPath();
+ WebResource resource = resources.getResource(path);
+ if (resource.isDirectory()) {
+ return resource.getCanonicalPath() + File.separatorChar;
+ } else {
+ return resource.getCanonicalPath();
+ }
} 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=1658804&r1=1658803&r2=1658804&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java
(original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContext.java Tue Feb
10 20:54:07 2015
@@ -937,6 +937,32 @@ public class TestStandardContext extends
Assert.assertNull(realPath);
}
+ /*
+ * Check real path for directories ends with File.separator for consistency
+ * with previous major versions.
+ */
+ @Test
+ public void testBug57556() 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);
+ // Doesn't exist so Tomcat will assume it is a file, not a directory.
+ doTestBug57556(testContext, "/foo", false);
+ }
+
+ private void doTestBug57556(Context testContext, String path, boolean
endsInSeparator) 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));
+ }
+ }
+
@Test
public void testBug56903() {
Context context = new StandardContext();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]