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
commit 8ee2289401be733dafbda9304b952f77a1c4dc61 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Jun 27 12:30:47 2024 +0100 Partial fix for BZ 69135 Include directives where the file attribute starts with "/" should be relative to the context ROOT (rather than the JAR root when the file with the include is packaged in a JAR). --- java/org/apache/jasper/compiler/Parser.java | 10 +++++++++- .../catalina/loader/TestVirtualWebappLoader.java | 4 ++-- test/org/apache/jasper/TestJspCompilationContext.java | 18 ++++++++++++++++++ test/webapp/WEB-INF/lib/bug69135-lib.jar | Bin 0 -> 2443 bytes test/webapp/bug6nnnn/bug69135.jsp | 18 ++++++++++++++++++ test/webapp/ok.tagf | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/java/org/apache/jasper/compiler/Parser.java b/java/org/apache/jasper/compiler/Parser.java index a9298d8e06..4678e8b642 100644 --- a/java/org/apache/jasper/compiler/Parser.java +++ b/java/org/apache/jasper/compiler/Parser.java @@ -344,7 +344,15 @@ class Parser implements TagConstants { } try { - parserController.parse(file, parent, jar); + /* + * Include directive defined by 1.10.3 which references 1.2.1 for the file attribute. As per 1.2.1, paths + * starting with "/" are context relative. + */ + if (file.startsWith("/")) { + parserController.parse(file, parent, null); + } else { + parserController.parse(file, parent, jar); + } } catch (FileNotFoundException ex) { err.jspError(start, "jsp.error.file.not.found", file); } catch (Exception ex) { diff --git a/test/org/apache/catalina/loader/TestVirtualWebappLoader.java b/test/org/apache/catalina/loader/TestVirtualWebappLoader.java index 8a158a9dd9..460341740d 100644 --- a/test/org/apache/catalina/loader/TestVirtualWebappLoader.java +++ b/test/org/apache/catalina/loader/TestVirtualWebappLoader.java @@ -89,7 +89,7 @@ public class TestVirtualWebappLoader extends TomcatBaseTest { loader.start(); String[] repos = loader.getLoaderRepositories(); - Assert.assertEquals(4,repos.length); + Assert.assertEquals(5,repos.length); loader.stop(); repos = loader.getLoaderRepositories(); @@ -98,7 +98,7 @@ public class TestVirtualWebappLoader extends TomcatBaseTest { // no leak loader.start(); repos = loader.getLoaderRepositories(); - Assert.assertEquals(4,repos.length); + Assert.assertEquals(5,repos.length); // clear loader ctx.setLoader(null); diff --git a/test/org/apache/jasper/TestJspCompilationContext.java b/test/org/apache/jasper/TestJspCompilationContext.java index 7c1b7866d3..ff5fbe34f5 100644 --- a/test/org/apache/jasper/TestJspCompilationContext.java +++ b/test/org/apache/jasper/TestJspCompilationContext.java @@ -71,4 +71,22 @@ public class TestJspCompilationContext extends TomcatBaseTest { Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(body.toString().contains("00 - OK")); } + + + /* + * Test case for https://bz.apache.org/bugzilla/show_bug.cgi?id=69135 + */ + @Test + public void testTagFileInJarIncludeAbsolute() throws Exception { + getTomcatInstanceTestWebapp(false, true); + + ByteChunk body = new ByteChunk(); + + int rc = getUrl("http://localhost:" + getPort() + + "/test/bug6nnnn/bug69135.jsp", body, null); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + Assert.assertTrue(body.toString(), body.toString().contains("00 - OK")); + + } } diff --git a/test/webapp/WEB-INF/lib/bug69135-lib.jar b/test/webapp/WEB-INF/lib/bug69135-lib.jar new file mode 100644 index 0000000000..433ffa286b Binary files /dev/null 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 new file mode 100644 index 0000000000..8f0bc85e82 --- /dev/null +++ b/test/webapp/bug6nnnn/bug69135.jsp @@ -0,0 +1,18 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@ taglib uri="http://tomcat.apache.org/bug69135-lib" prefix="bz69135" %> +<bz69135:absolute index="00" /> \ No newline at end of file diff --git a/test/webapp/ok.tagf b/test/webapp/ok.tagf new file mode 100644 index 0000000000..eb32ad5376 --- /dev/null +++ b/test/webapp/ok.tagf @@ -0,0 +1,16 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%>OK \ 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