This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 28d7d14  https://bz.apache.org/bugzilla/show_bug.cgi?id=63275 enc 
getContextPath
28d7d14 is described below

commit 28d7d143cb9f69982db72b5a648f007b1fa138cb
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 fd91356..9bafe6f 100644
--- a/java/org/apache/catalina/core/ApplicationDispatcher.java
+++ b/java/org/apache/catalina/core/ApplicationDispatcher.java
@@ -382,7 +382,7 @@ final class ApplicationDispatcher implements 
AsyncDispatcher, RequestDispatcher
                 wrequest.setAttribute(FORWARD_MAPPING, mapping);
             }
 
-            wrequest.setContextPath(context.getPath());
+            wrequest.setContextPath(context.getEncodedPath());
             wrequest.setRequestURI(requestURI);
             wrequest.setServletPath(servletPath);
             wrequest.setPathInfo(pathInfo);
@@ -636,7 +636,7 @@ final class ApplicationDispatcher implements 
AsyncDispatcher, RequestDispatcher
         }
         wrequest.setAttribute(ASYNC_MAPPING, mapping);
 
-        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 db627fb..b5c6e0c 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 c7b8cdd..0fce5c0 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

Reply via email to