This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 2072077 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63964 Cached URLs 2072077 is described below commit 207207735cc88e221254c6f4c01782f8df173096 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Nov 26 18:49:07 2019 +0000 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63964 Cached URLs Correct a regression in the static resource caching changes introduced to fix an issue with Jasper not showing updated JSOP files. URLs constructed from URLs obtained from the cache could not be used to access resources. --- .../catalina/webresources/CachedResource.java | 12 ++++- .../catalina/webresources/TestCachedResource.java | 52 ++++++++++++++++++++++ webapps/docs/changelog.xml | 5 +++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/java/org/apache/catalina/webresources/CachedResource.java b/java/org/apache/catalina/webresources/CachedResource.java index b1caf07..6b3e615 100644 --- a/java/org/apache/catalina/webresources/CachedResource.java +++ b/java/org/apache/catalina/webresources/CachedResource.java @@ -423,7 +423,17 @@ public class CachedResource implements WebResource { @Override protected URLConnection openConnection(URL u) throws IOException { - return new CachedResourceURLConnection(resourceURL, root, webAppPath, usesClassLoaderResources); + // This deliberately uses ==. If u isn't the URL object this + // URLStreamHandler was constructed for we do not want to use this + // URLStreamHandler to create a connection. + if (u == resourceURL) { + return new CachedResourceURLConnection(resourceURL, root, webAppPath, usesClassLoaderResources); + } else { + // The stream handler has been inherited by a URL that was + // constructed from a cache URL. We need to break that link. + URL constructedURL = new URL(u.toExternalForm()); + return constructedURL.openConnection(); + } } } diff --git a/test/org/apache/catalina/webresources/TestCachedResource.java b/test/org/apache/catalina/webresources/TestCachedResource.java new file mode 100644 index 0000000..e75819b --- /dev/null +++ b/test/org/apache/catalina/webresources/TestCachedResource.java @@ -0,0 +1,52 @@ +/* + * 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. + */ +package org.apache.catalina.webresources; + +import java.io.File; +import java.io.InputStream; +import java.net.URL; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.WebResourceRoot; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; + +public class TestCachedResource extends TomcatBaseTest { + + // https://bz.apache.org/bugzilla/show_bug.cgi?id=63872 + @Test + public void testUrlFileFromDirectory() throws Exception { + + Tomcat tomcat = getTomcatInstance(); + File docBase = new File("test/webresources/dir1"); + Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath()); + tomcat.start(); + + WebResourceRoot root = ctx.getResources(); + + URL d1 = root.getResource("/d1").getURL(); + + URL d1f1 = new URL(d1, "d1-f1.txt"); + + try (InputStream is = d1f1.openStream()) { + Assert.assertNotNull(is); + } + } +} diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 57c30ac..8452d2e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -52,6 +52,11 @@ CSRF nonce request parameter name to be customized. (schultz) </add> + <fix> + <bug>63964</bug>: Correct a regression in the static resource caching + changes introduced in 9.0.28. URLs constructed from URLs obtained from + the cache could not be used to access resources. (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