This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 0ceffea704 Fix BZ 70375 - getResources() ignores names with a leading
'/'
0ceffea704 is described below
commit 0ceffea70417b789fb2fa1889a86d8bf700c65fc
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 5576419799..d0afc8046c 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -1010,10 +1010,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 bcde963fbb..37cded7966 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 6753cf1f64..7960e08d3c 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]