Deal with spaces in file references

Fixes gh-1169
This commit is contained in:
Phillip Webb 2014-06-25 15:43:07 -07:00
parent 7654259f80
commit 7e7733d45d
4 changed files with 8 additions and 4 deletions

View File

@ -25,6 +25,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -518,7 +519,8 @@ public class PropertiesLauncher extends Launcher {
}
}
else {
lib.add(0, new ExplodedArchive(new File(url.getFile())));
String filename = URLDecoder.decode(url.getFile(), "UTF-8");
lib.add(0, new ExplodedArchive(new File(filename)));
}
}
}

View File

@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.net.URLStreamHandler;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -151,7 +152,7 @@ public class Handler extends URLStreamHandler {
throw new IllegalStateException("Not a file URL");
}
String path = name.substring(FILE_PROTOCOL.length());
File file = new File(path);
File file = new File(URLDecoder.decode(path, "UTF-8"));
Map<File, JarFile> cache = rootFileCache.get();
JarFile jarFile = (cache == null ? null : cache.get(file));
if (jarFile == null) {

View File

@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@ -106,7 +107,8 @@ public class ExplodedArchiveTests {
@Test
public void getUrl() throws Exception {
URL url = this.archive.getUrl();
assertThat(new File(url.toURI()), equalTo(new File(this.rootFolder.toURI())));
assertThat(new File(URLDecoder.decode(url.getFile(), "UTF-8")),
equalTo(this.rootFolder));
}
@Test

View File

@ -97,7 +97,6 @@ public class JarFileTests {
assertThat(urlClassLoader.getResource("special/\u00EB.dat"), notNullValue());
assertThat(urlClassLoader.getResource("d/9.dat"), notNullValue());
jarFile.close();
}
@Test