diff options
author | Thomas Watson | 2013-04-02 15:46:31 +0000 |
---|---|---|
committer | Thomas Watson | 2013-04-02 15:46:31 +0000 |
commit | 1abecd574ff7536e7e50b74b4686921f44249723 (patch) | |
tree | 94f364ca11b5eb89018a908e85308903fbbc5fb6 | |
parent | b7ccceae37d63c2a81a92eca9393557b0cd4f7c3 (diff) | |
download | rt.equinox.bundles-1abecd574ff7536e7e50b74b4686921f44249723.tar.gz rt.equinox.bundles-1abecd574ff7536e7e50b74b4686921f44249723.tar.xz rt.equinox.bundles-1abecd574ff7536e7e50b74b4686921f44249723.zip |
Bug 370547 - CloseableURLClassLoader should handle both encoded and unencoded URLs
3 files changed, 53 insertions, 13 deletions
diff --git a/bundles/org.eclipse.equinox.servletbridge/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.servletbridge/META-INF/MANIFEST.MF index b19c9b61b..1bd3d24ad 100644 --- a/bundles/org.eclipse.equinox.servletbridge/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.servletbridge/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.equinox.servletbridge;singleton:=true -Bundle-Version: 1.2.200.qualifier +Bundle-Version: 1.2.300.qualifier Bundle-Localization: plugin Import-Package: javax.servlet;version="2.3.0", javax.servlet.http;version="2.3.0" diff --git a/bundles/org.eclipse.equinox.servletbridge/pom.xml b/bundles/org.eclipse.equinox.servletbridge/pom.xml index 863ba0a3f..969047ad7 100644 --- a/bundles/org.eclipse.equinox.servletbridge/pom.xml +++ b/bundles/org.eclipse.equinox.servletbridge/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.servletbridge</artifactId> - <version>1.2.200-SNAPSHOT</version> + <version>1.2.300-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java index f29efbf4b..03bd8f902 100644 --- a/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java +++ b/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,6 +35,8 @@ public class CloseableURLClassLoader extends URLClassLoader { static final String DOT_CLASS = ".class"; //$NON-NLS-1$ static final String BANG_SLASH = "!/"; //$NON-NLS-1$ static final String JAR = "jar"; //$NON-NLS-1$ + private static final String UNC_PREFIX = "//"; //$NON-NLS-1$ + private static final String SCHEME_FILE = "file"; //$NON-NLS-1$ // @GuardedBy("loaders") final ArrayList loaders = new ArrayList(); // package private to avoid synthetic access. @@ -174,16 +176,54 @@ public class CloseableURLClassLoader extends URLClassLoader { } // @GuardedBy("loaders") - private void safeAddLoader(URL url) { - String path = url.getPath(); - File file = new File(path); - if (file.exists()) { - try { - loaders.add(new CloseableJarFileLoader(file, verifyJars)); - } catch (IOException e) { - // ignore + private boolean safeAddLoader(URL url) { + //assume all illegal characters have been properly encoded, so use URI class to unencode + try { + File file = new File(toURI(url)); + if (file.exists()) { + try { + loaders.add(new CloseableJarFileLoader(file, verifyJars)); + return true; + } catch (IOException e) { + // ignore + } } + } catch (URISyntaxException e1) { + // ignore + } + + return false; + } + + private static URI toURI(URL url) throws URISyntaxException { + if (!SCHEME_FILE.equals(url.getProtocol())) { + throw new IllegalArgumentException("bad prototcol: " + url.getProtocol()); //$NON-NLS-1$ + } + //URL behaves differently across platforms so for file: URLs we parse from string form + String pathString = url.toExternalForm().substring(5); + //ensure there is a leading slash to handle common malformed URLs such as file:c:/tmp + if (pathString.indexOf('/') != 0) + pathString = '/' + pathString; + else if (pathString.startsWith(UNC_PREFIX) && !pathString.startsWith(UNC_PREFIX, 2)) { + //URL encodes UNC path with two slashes, but URI uses four (see bug 207103) + pathString = ensureUNCPath(pathString); + } + return new URI(SCHEME_FILE, null, pathString, null); + } + + /** + * Ensures the given path string starts with exactly four leading slashes. + */ + private static String ensureUNCPath(String path) { + int len = path.length(); + StringBuffer result = new StringBuffer(len); + for (int i = 0; i < 4; i++) { + // if we have hit the first non-slash character, add another leading slash + if (i >= len || result.length() > 0 || path.charAt(i) != '/') + result.append('/'); } + result.append(path); + return result.toString(); } private static URL[] excludeFileJarURLS(URL[] urls) { @@ -370,8 +410,8 @@ public class CloseableURLClassLoader extends URLClassLoader { if (closed) throw new IllegalStateException("Cannot add url. CloseableURLClassLoader is closed."); //$NON-NLS-1$ loaderURLs.add(url); - safeAddLoader(url); - return; + if (safeAddLoader(url)) + return; } } super.addURL(url); |