Re: svn commit: r1658804 - in /tomcat/trunk: java/org/apache/catalina/core/StandardContext.java test/org/apache/catalina/core/TestStandardContext.java
2015-02-10 23:54 GMT+03:00 ma...@apache.org: 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=1658804r1=1658803r2=1658804view=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; 1) I think it is better to check whether it ends with separatorChar first. E.g. if a Windows drive root is deployed as a web application. I think that getCanonicalPath() will end with a backslash. T:\ is the root directory of drive T, T: is the current directory on drive T. 2) I think that this changes the value of getRealPath(), I have not tested whether it was ending with a slash in the old versions. +} else { +return resource.getCanonicalPath(); +} } catch (IllegalArgumentException iae) { // ServletContext.getRealPath() does not allow this to be thrown } Best regards, Konstantin Kolinko - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
svn commit: r1658804 - in /tomcat/trunk: java/org/apache/catalina/core/StandardContext.java test/org/apache/catalina/core/TestStandardContext.java
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=1658804r1=1658803r2=1658804view=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=1658804r1=1658803r2=1658804view=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: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
Re: svn commit: r1658804 - in /tomcat/trunk: java/org/apache/catalina/core/StandardContext.java test/org/apache/catalina/core/TestStandardContext.java
On 10/02/2015 21:08, Konstantin Kolinko wrote: 2015-02-10 23:54 GMT+03:00 ma...@apache.org: 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=1658804r1=1658803r2=1658804view=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; 1) I think it is better to check whether it ends with separatorChar first. E.g. if a Windows drive root is deployed as a web application. I think that getCanonicalPath() will end with a backslash. It does. Additional tests and a fix on the way. T:\ is the root directory of drive T, T: is the current directory on drive T. 2) I think that this changes the value of getRealPath(), I've added this to the tests. The behaviour is consistent. Mark - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org