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

markt 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 a048642095 Fix static resources in a JAR file when using a bloom 
filter.
a048642095 is described below

commit a048642095141f0cb03a7b569f4e1873da4a4198
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 12 13:24:21 2024 +0100

    Fix static resources in a JAR file when using a bloom filter.
    
    Based on pull request #730 provided by bergander.
---
 .../webresources/AbstractArchiveResourceSet.java        |   6 ++++--
 .../webresources/TestAbstractArchiveResourceSet.java    |  16 ++++++++++++++++
 test/webresources/static-resources.jar                  | Bin 0 -> 823 bytes
 webapps/docs/changelog.xml                              |   5 +++++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java 
b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
index 51d9d24100..5eb08c6562 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
@@ -205,8 +205,10 @@ public abstract class AbstractArchiveResourceSet extends 
AbstractResourceSet {
          * If jarContents reports that this resource definitely does not 
contain the path, we can end this method and
          * move on to the next jar.
          */
-        if (jarContents != null && !jarContents.mightContainResource(path, 
webAppMount)) {
-            return new EmptyResource(root, path);
+        if (jarContents != null &&
+                !jarContents.mightContainResource(getInternalPath().isEmpty() 
? path : getInternalPath() + path,
+                         webAppMount)) {
+                return new EmptyResource(root, path);
         }
 
         /*
diff --git 
a/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java 
b/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java
index ba5f742d65..c84f58575c 100644
--- a/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java
+++ b/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java
@@ -104,6 +104,22 @@ public class TestAbstractArchiveResourceSet {
         Assert.assertNull(getJarContents(jarResourceSet));
     }
 
+    @Test
+    public void testBloomFilterWithJarResource() throws Exception {
+        WebResourceRoot root = new TesterWebResourceRoot();
+
+        
root.setArchiveIndexStrategy(WebResourceRoot.ArchiveIndexStrategy.BLOOM.name());
+
+        File file = new File("test/webresources/static-resources.jar");
+
+        JarResourceSet jarResourceSet = new JarResourceSet(root, "/", 
file.getAbsolutePath(), "/META-INF/resources");
+        jarResourceSet.getArchiveEntries(false);
+        Assert.assertNotNull(getJarContents(jarResourceSet));
+
+        WebResource r1 = jarResourceSet.getResource("/index.html");
+        Assert.assertTrue(r1.isFile());
+    }
+
     private JarContents getJarContents(Object target)
         throws IllegalArgumentException, IllegalAccessException, 
NoSuchFieldException, SecurityException {
         Field field = 
AbstractArchiveResourceSet.class.getDeclaredField("jarContents");
diff --git a/test/webresources/static-resources.jar 
b/test/webresources/static-resources.jar
new file mode 100644
index 0000000000..8403903010
Binary files /dev/null and b/test/webresources/static-resources.jar differ
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0bd753cd9e..7a505a451c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -128,6 +128,11 @@
         instances of <code>LinkageError</code> to be reported as
         <code>ClassNotFoundException</code>. (markt)
       </fix>
+      <fix>
+        Ensure that static resources deployed via a JAR file remain accessible
+        when the context is configured to use a bloom filter. Based on pull
+        request <pr>730</pr> provided by bergander. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to