This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new bb32a1dcb1 Fix BZ 70375 - getResources() ignores names with a leading
'/'
bb32a1dcb1 is described below
commit bb32a1dcb107f7d89f163511a6658d8017c5d06b
Author: Arturo Bernal <[email protected]>
AuthorDate: Mon Nov 23 20:22:07 2026 +0100
Fix BZ 70375 - getResources() ignores names with a leading '/'
findResources() returned an empty enumeration for names starting with
'/', while findResource(), getResource() and getResourceAsStream() still
accept such names and find the resource. getResources() and
getResource() therefore disagreed for the same name, and applications
passing such names to getResources() no longer found their resources.
Remove the check so that findResources() handles these names in the
same way as the other lookups, and update the tests to assert that
findResources() and getResources() return the same resource as
findResource() and getResource().
---
java/org/apache/catalina/loader/WebappClassLoaderBase.java | 4 ----
test/org/apache/catalina/loader/TestWebappClassLoader.java | 6 ++++++
webapps/docs/changelog.xml | 7 +++++++
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
index c014323e9b..e0a8b828a8 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -1020,10 +1020,6 @@ public abstract class WebappClassLoaderBase extends
URLClassLoader
checkStateForResourceLoading(name);
- if (name == null || name.startsWith("/")) {
- return Collections.emptyEnumeration();
- }
-
String path = nameToPath(name);
WebResource[] webResources;
diff --git a/test/org/apache/catalina/loader/TestWebappClassLoader.java
b/test/org/apache/catalina/loader/TestWebappClassLoader.java
index 839e906309..c83c73530d 100644
--- a/test/org/apache/catalina/loader/TestWebappClassLoader.java
+++ b/test/org/apache/catalina/loader/TestWebappClassLoader.java
@@ -256,6 +256,9 @@ public class TestWebappClassLoader extends TomcatBaseTest {
Enumeration<URL> urls =
cl.findResources("/org/apache/tomcat/Bug58096.java");
Assert.assertNotNull(urls);
+ // Consistent with findResource()
+ Assert.assertTrue(urls.hasMoreElements());
+
Assert.assertEquals(cl.findResource("/org/apache/tomcat/Bug58096.java"),
urls.nextElement());
Assert.assertFalse(urls.hasMoreElements());
}
@@ -270,6 +273,9 @@ public class TestWebappClassLoader extends TomcatBaseTest {
Enumeration<URL> urls =
cl.getResources("/org/apache/tomcat/Bug58096.java");
Assert.assertNotNull(urls);
+ // Consistent with getResource()
+ Assert.assertTrue(urls.hasMoreElements());
+
Assert.assertEquals(cl.getResource("/org/apache/tomcat/Bug58096.java"),
urls.nextElement());
Assert.assertFalse(urls.hasMoreElements());
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 524d6896ce..e93074e095 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -130,6 +130,13 @@
Expand the user name normalisation options available in the
<code>LockOutRealm</code>. (markt)
</fix>
+ <fix>
+ <bug>70375</bug>: Restore support for resource names that start with
+ <code>/</code> in <code>WebappClassLoaderBase.getResources()</code> and
+ <code>findResources()</code>, so that they find the same resources as
+ <code>getResource()</code> and <code>getResourceAsStream()</code>.
+ Pull request <pr>1269</pr> provided by Arturo Bernal.
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]