fix bug involving paths with spaces
This commit is contained in:
parent
72f85ba2a9
commit
182363bf88
@ -34,5 +34,14 @@ public class FileProviderTest {
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURLWithSpace() throws MalformedURLException {
|
||||
URL url = new URL("file:///With%20Space/File.jar");
|
||||
String expected = PlatformUtil.onWindows() ? "/C:/With Space/File.jar" : "/With Space/File.jar";
|
||||
// exercise:
|
||||
String actual = (new FileProvider()).filePathFromURL(url);
|
||||
// verify:
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -14,9 +14,11 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipException;
|
||||
@ -24,6 +26,7 @@ import java.util.zip.ZipException;
|
||||
import com.ibm.wala.classLoader.JarFileModule;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.NestedJarFileModule;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
* This class provides files that are packaged with this plug-in
|
||||
@ -182,8 +185,13 @@ public class FileProvider {
|
||||
// This solution works. See discussion at
|
||||
// http://stackoverflow.com/questions/4494063/how-to-avoid-java-net-urisyntaxexception-in-url-touri
|
||||
URI uri = new File(url.getPath()).toURI();
|
||||
String filePath = uri.getPath();
|
||||
return filePath;
|
||||
try {
|
||||
return URLDecoder.decode(uri.getPath(), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// this really shouldn't happen
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user