Author: markt Date: Tue Mar 24 10:58:14 2015 New Revision: 1668843 URL: http://svn.apache.org/r1668843 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57736 Switch to */ in Tomcat's custom format for URLs for resources in JARs packed in WARs rather than ^/ since ^ is not a valid character for URLs as per RFC 2396. The ^/ format remains support in case apps are using that format directly
Added: tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java (with props) tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandlerIntegration.java (with props) Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLConnection.java Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java?rev=1668843&r1=1668842&r2=1668843&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java (original) +++ tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java Tue Mar 24 10:58:14 2015 @@ -37,7 +37,7 @@ public class JarWarResource extends Abst public JarWarResource(AbstractArchiveResourceSet archiveResourceSet, String webAppPath, String baseUrl, JarEntry jarEntry, String archivePath) { - super(archiveResourceSet, webAppPath, "jar:war:" + baseUrl + "^/" + archivePath, + super(archiveResourceSet, webAppPath, "jar:war:" + baseUrl + "*/" + archivePath, jarEntry, "jar:" + baseUrl + "!/" + archivePath); this.archivePath = archivePath; } Modified: tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java?rev=1668843&r1=1668842&r2=1668843&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java (original) +++ tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java Tue Mar 24 10:58:14 2015 @@ -30,7 +30,11 @@ public class WarURLStreamHandler extends // Only the path needs to be changed String path = "jar:" + spec.substring(4); - path = path.replaceFirst("\\^/", "!/"); + if (path.contains("*/")) { + path = path.replaceFirst("\\*/", "!/"); + } else { + path = path.replaceFirst("\\^/", "!/"); + } setURL(u, u.getProtocol(), "", -1, null, null, path, null, null); Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java?rev=1668843&r1=1668842&r2=1668843&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java Tue Mar 24 10:58:14 2015 @@ -53,7 +53,7 @@ public class JarFactory { // Assume this is pointing to a JAR file within a WAR. Java doesn't // support jar:jar:file:... so switch to Tomcat's war:file:... baseExternal = baseExternal.replaceFirst("^jar:", "war:"); - baseExternal = baseExternal.replaceFirst("!/", "^/"); + baseExternal = baseExternal.replaceFirst("!/", "*/"); } return new URL("jar:" + baseExternal + "!/" + entryName); Modified: tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLConnection.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLConnection.java?rev=1668843&r1=1668842&r2=1668843&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLConnection.java (original) +++ tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLConnection.java Tue Mar 24 10:58:14 2015 @@ -38,7 +38,7 @@ public class TestWarURLConnection { String fileUrl = f.toURI().toURL().toString(); URL indexHtmlUrl = new URL("jar:war:" + fileUrl + - "^/WEB-INF/lib/test.jar!/META-INF/resources/index.html"); + "*/WEB-INF/lib/test.jar!/META-INF/resources/index.html"); URLConnection urlConn = indexHtmlUrl.openConnection(); urlConn.connect(); Added: tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java?rev=1668843&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java (added) +++ tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java Tue Mar 24 10:58:14 2015 @@ -0,0 +1,50 @@ +/* + * 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.net.URL; +import java.net.URLConnection; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestWarURLStreamHandler { + + @Before + public void register() { + TomcatURLStreamHandlerFactory.register(); + } + + + @Test + public void testOldFormat() throws Exception { + File f = new File("test/webresources/war-url-connection.war"); + String fileUrl = f.toURI().toURL().toString(); + + URL indexHtmlUrl = new URL("jar:war:" + fileUrl + + "^/WEB-INF/lib/test.jar!/META-INF/resources/index.html"); + + URLConnection urlConn = indexHtmlUrl.openConnection(); + urlConn.connect(); + + int size = urlConn.getContentLength(); + + Assert.assertEquals(137, size); + } +} Propchange: tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandlerIntegration.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandlerIntegration.java?rev=1668843&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandlerIntegration.java (added) +++ tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandlerIntegration.java Tue Mar 24 10:58:14 2015 @@ -0,0 +1,51 @@ +/* + * 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.net.URL; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.core.StandardHost; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; + +public class TestWarURLStreamHandlerIntegration extends TomcatBaseTest { + + @Test + public void testToURI() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File docBase = new File("test/webresources/war-url-connection.war"); + Context context = tomcat.addWebapp("/test", docBase.getAbsolutePath()); + + ((StandardHost) tomcat.getHost()).setUnpackWARs(false); + + tomcat.start(); + + URL url = context.getServletContext().getResource("/index.html"); + try { + url.toURI(); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(); + } + } +} Propchange: tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandlerIntegration.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org