Skip to content

Commit

Permalink
Fix bz 64373. Ensure tag file unpacked from WAR can be found.
Browse files Browse the repository at this point in the history
Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=64373
Patch provided by Karl von Randow
  • Loading branch information
markt-asf committed Apr 27, 2020
1 parent 4684537 commit 224fb6c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
8 changes: 8 additions & 0 deletions java/org/apache/jasper/compiler/TagLibraryInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ private TagInfo createTagInfo(TagXml tagXml) throws JasperException {
tagXml.hasDynamicAttributes());
}

@SuppressWarnings("null") // Impossible for path to be null at warning
private TagFileInfo createTagFileInfo(TagFileXml tagFileXml, Jar jar) throws JasperException {

String name = tagFileXml.getName();
Expand All @@ -325,6 +326,13 @@ private TagFileInfo createTagFileInfo(TagFileXml tagFileXml, Jar jar) throws Jas
err.jspError("jsp.error.tagfile.illegalPath", path);
}

if (jar == null && path.startsWith("/META-INF/tags")) {
// This is a tag file that was packaged in a JAR that has been
// unpacked into /WEB-INF/classes (probably by an IDE). Adjust the
// path accordingly.
path = "/WEB-INF/classes" + path;
}

TagInfo tagInfo =
TagFileProcessor.parseTagFileDirectives(parserController, name, path, jar, this);
return new TagFileInfo(name, path, tagInfo);
Expand Down
15 changes: 15 additions & 0 deletions test/org/apache/jasper/compiler/TestTagLibraryInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ public void testRelativeTldLocation() throws Exception {
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
}


/*
* https://bz.apache.org/bugzilla/show_bug.cgi?id=64373
*/
@Test
public void testTldFromExplodedWar() throws Exception {
getTomcatInstanceTestWebapp(false, true);

ByteChunk res = new ByteChunk();

int rc = getUrl("http://localhost:" + getPort() +
"/test/bug6nnnn/bug64373.jsp", res, null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
}

}
31 changes: 31 additions & 0 deletions test/webapp/WEB-INF/classes/META-INF/bug64373.tld
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
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 xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>bug64373</short-name>
<uri>http://tomcat.apache.org/bug64373</uri>

<tag-file>
<name>bug64373</name>
<path>/META-INF/tags/bug64373.tag</path>
</tag-file>

</taglib>
17 changes: 17 additions & 0 deletions test/webapp/WEB-INF/classes/META-INF/tags/bug64373.tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%--
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.
--%><%@ tag %><%@
tag body-content="empty" %><p>OK</p>
23 changes: 23 additions & 0 deletions test/webapp/bug6nnnn/bug64373.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%--
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/bug64373" prefix="bugs" %>
<html>
<head><title>Bug 64373 test case</title></head>
<body>
<bugs:bug64373 />
</body>
</html>
5 changes: 5 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
Add more descriptive error message in DefaultServlet for SC_NOT_FOUND.
(michaelo)
</add>
<fix>
<bug>64373</bug>: When a tag file is packaged in a WAR and then that WAR
is unpacked in <code>/WEB-INF/classes</code> ensure that the tag file
can still be found. Patch provided by Karl von Randow. (markt)
</fix>
</changelog>
</subsection>
<subsection name="Web applications">
Expand Down

0 comments on commit 224fb6c

Please sign in to comment.