This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 4f1b667 https://bz.apache.org/bugzilla/show_bug.cgi?id=63275 enc getContextPath 4f1b667 is described below commit 4f1b667f15e6ed46d8704687dab5da73e7404552 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Mar 21 14:46:14 2019 +0000 https://bz.apache.org/bugzilla/show_bug.cgi?id=63275 enc getContextPath When using a RequestDispatcher ensure that HttpServletRequest.getContextPath() returns an encoded path in the dispatched request. --- java/org/apache/catalina/core/ApplicationDispatcher.java | 4 ++-- .../core/TestApplicationContextGetRequestDispatcher.java | 11 ++++++++--- webapps/docs/changelog.xml | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index cbaa808..522e4a7 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -371,7 +371,7 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher wrequest.setAttribute(RequestDispatcher.FORWARD_MAPPING, hrequest.getHttpServletMapping()); } - wrequest.setContextPath(context.getPath()); + wrequest.setContextPath(context.getEncodedPath()); wrequest.setRequestURI(requestURI); wrequest.setServletPath(servletPath); wrequest.setPathInfo(pathInfo); @@ -618,7 +618,7 @@ final class ApplicationDispatcher implements AsyncDispatcher, RequestDispatcher wrequest.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, getCombinedPath()); wrequest.setAttribute(AsyncContext.ASYNC_MAPPING, hrequest.getHttpServletMapping()); - wrequest.setContextPath(context.getPath()); + wrequest.setContextPath(context.getEncodedPath()); wrequest.setRequestURI(requestURI); wrequest.setServletPath(servletPath); wrequest.setPathInfo(pathInfo); diff --git a/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java b/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java index e75e87c..c83f95f 100644 --- a/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java +++ b/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java @@ -375,7 +375,7 @@ public class TestApplicationContextGetRequestDispatcher extends TomcatBaseTest { Tomcat tomcat = getTomcatInstance(); // No file system docBase required - Context ctx = tomcat.addContext("/test", null); + Context ctx = tomcat.addContext("/test\u6771\u4eac", null); ctx.setDispatchersUseEncodedPaths(useEncodedDispatchPaths); // Add a default servlet to return 404 for not found resources @@ -400,7 +400,7 @@ public class TestApplicationContextGetRequestDispatcher extends TomcatBaseTest { StringBuilder url = new StringBuilder("http://localhost:"); url.append(getPort()); - url.append("/test"); + url.append("/test%E6%9D%B1%E4%BA%AC"); url.append(startPath); if (startQueryString != null) { url.append('?'); @@ -467,7 +467,12 @@ public class TestApplicationContextGetRequestDispatcher extends TomcatBaseTest { throws ServletException, IOException { resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); - resp.getWriter().print(OK); + String contextPath = req.getContextPath(); + if ("/test%E6%9D%B1%E4%BA%AC".equals(contextPath)) { + resp.getWriter().print(OK); + } else { + resp.getWriter().print("FAIL - ContextPath"); + } String qs = req.getQueryString(); if (qs != null) { resp.getWriter().print(qs); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6507864..b49a62c 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -74,6 +74,11 @@ href="https://bugs.openjdk.java.net/browse/JDK-8194653">JDK-8194653</a>) that may cause a dead-lock when Tomcat starts. (markt) </fix> + <fix> + <bug>63275</bug>: When using a <code>RequestDispatcher</code> ensure + that <code>HttpServletRequest.getContextPath()</code> returns an encoded + path in the dispatched request. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org