This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new a48767b Fix BZ 56890 - Clarification of ServletContext.getRealPath(String) a48767b is described below commit a48767b4e8c513b819fb5fa13505c15922969813 Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Nov 30 13:35:59 2020 +0000 Fix BZ 56890 - Clarification of ServletContext.getRealPath(String) https://bz.apache.org/bugzilla/show_bug.cgi?id=56890 If the provided path doesn't start with "/", process the method call as if "/" was appended to the beginning of the provided path. --- java/org/apache/catalina/core/ApplicationContext.java | 16 ++++++---------- webapps/docs/changelog.xml | 8 ++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index 2bc9a48..697b956 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -526,7 +526,7 @@ public class ApplicationContext implements ServletContext { @Override public URL getResource(String path) throws MalformedURLException { - String validatedPath = validateResourcePath(path, false); + String validatedPath = validateResourcePath(path, !GET_RESOURCE_REQUIRE_SLASH); if (validatedPath == null) { throw new MalformedURLException( @@ -545,7 +545,7 @@ public class ApplicationContext implements ServletContext { @Override public InputStream getResourceAsStream(String path) { - String validatedPath = validateResourcePath(path, false); + String validatedPath = validateResourcePath(path, !GET_RESOURCE_REQUIRE_SLASH); if (validatedPath == null) { return null; @@ -564,20 +564,16 @@ public class ApplicationContext implements ServletContext { * Returns null if the input path is not valid or a path that will be * acceptable to resources.getResource(). */ - private String validateResourcePath(String path, boolean allowEmptyPath) { + private String validateResourcePath(String path, boolean addMissingInitialSlash) { if (path == null) { return null; } - if (path.length() == 0 && allowEmptyPath) { - return path; - } - if (!path.startsWith("/")) { - if (GET_RESOURCE_REQUIRE_SLASH) { - return null; - } else { + if (addMissingInitialSlash) { return "/" + path; + } else { + return null; } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 8991250..f95de76 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -112,6 +112,14 @@ the return value of <code>ServletRequest.getRemoteAddr()</code> rather than always returning a value for the proxy. (markt) </fix> + <fix> + <bug>56890</bug>: Align the behaviour of + <code>ServletContext.getRealPath(String path)</code> with the recent + clarification from the Servlet specification project. If the path + parameter does not start with <code>/</code> then Tomcat processes the + call as if <code>/</code> is appended to the beginning of the + provided path. (markt) + </fix> <add> <bug>64080</bug>: Enhance the graceful shutdown feature. Includes a new option for <code>StandardService</code>, --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org