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

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

commit be232ad503db678c7326d8faba7466f6c36b11df
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 27 14:52:59 2024 +0100

    Expand BZ 69135 fix - fix relative includes inside JAR file
---
 java/org/apache/jasper/compiler/ParserController.java |   5 ++++-
 test/org/apache/jasper/TestJspCompilationContext.java |   6 +++++-
 test/webapp/WEB-INF/lib/bug69135-lib.jar              | Bin 2443 -> 7365 bytes
 test/webapp/bug6nnnn/bug69135.jsp                     |   3 ++-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/jasper/compiler/ParserController.java 
b/java/org/apache/jasper/compiler/ParserController.java
index 01e2b2a336..1b92d60b98 100644
--- a/java/org/apache/jasper/compiler/ParserController.java
+++ b/java/org/apache/jasper/compiler/ParserController.java
@@ -20,6 +20,7 @@ import java.io.BufferedInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.nio.file.Paths;
 import java.util.ArrayDeque;
 import java.util.Deque;
 
@@ -519,7 +520,9 @@ class ParserController implements TagConstants {
     private String resolveFileName(String inFileName) {
         String fileName = inFileName.replace('\\', '/');
         boolean isAbsolute = fileName.startsWith("/");
-        fileName = isAbsolute ? fileName : baseDirStack.peekFirst() + fileName;
+        if (!isAbsolute) {
+            fileName = Paths.get(baseDirStack.peekFirst() + 
fileName).normalize().toString();
+        }
         String baseDir = fileName.substring(0, fileName.lastIndexOf('/') + 1);
         baseDirStack.addFirst(baseDir);
         return fileName;
diff --git a/test/org/apache/jasper/TestJspCompilationContext.java 
b/test/org/apache/jasper/TestJspCompilationContext.java
index c86f18c8c4..bfd1671132 100644
--- a/test/org/apache/jasper/TestJspCompilationContext.java
+++ b/test/org/apache/jasper/TestJspCompilationContext.java
@@ -77,7 +77,7 @@ public class TestJspCompilationContext extends TomcatBaseTest 
{
      * Test case for https://bz.apache.org/bugzilla/show_bug.cgi?id=69135
      */
     @Test
-    public void testTagFileInJarIncludeAbsolute() throws Exception {
+    public void testTagFileInJarIncludesValid() throws Exception {
         getTomcatInstanceTestWebapp(false, true);
 
         ByteChunk body = new ByteChunk();
@@ -86,7 +86,11 @@ public class TestJspCompilationContext extends 
TomcatBaseTest {
                 "/test/bug6nnnn/bug69135.jsp", body, null);
 
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+
+        // Context relative include (starts with "/")
         Assert.assertTrue(body.toString(), body.toString().contains("00 - 
OK"));
 
+        // Resource relative include (does not start with "/")
+        Assert.assertTrue(body.toString(), body.toString().contains("01 - 
OK"));
     }
 }
diff --git a/test/webapp/WEB-INF/lib/bug69135-lib.jar 
b/test/webapp/WEB-INF/lib/bug69135-lib.jar
index 433ffa286b..9080642316 100644
Binary files a/test/webapp/WEB-INF/lib/bug69135-lib.jar and 
b/test/webapp/WEB-INF/lib/bug69135-lib.jar differ
diff --git a/test/webapp/bug6nnnn/bug69135.jsp 
b/test/webapp/bug6nnnn/bug69135.jsp
index 8f0bc85e82..98163fca02 100644
--- a/test/webapp/bug6nnnn/bug69135.jsp
+++ b/test/webapp/bug6nnnn/bug69135.jsp
@@ -15,4 +15,5 @@
   limitations under the License.
 --%>
 <%@ taglib uri="http://tomcat.apache.org/bug69135-lib"; prefix="bz69135" %>
-<bz69135:absolute index="00" />
\ No newline at end of file
+<bz69135:absolute index="00" />
+<bz69135:relative-valid index="01" />
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to