support non-canonical resource paths in UrlClassLoader

This commit is contained in:
peter
2016-09-19 12:04:51 +02:00
parent 2c2e9b76d1
commit 66f58bbf75
2 changed files with 13 additions and 2 deletions
@@ -18,6 +18,7 @@ package com.intellij.util.lang;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.win32.IdeaWin32;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
@@ -281,8 +282,7 @@ public class UrlClassLoader extends ClassLoader {
@Nullable
private Resource _getResource(final String name) {
String n = name;
n = StringUtil.trimStart(n, "/");
String n = StringUtil.trimStart(FileUtil.toCanonicalUriPath(name), "/");
return getClassPath().getResource(n, true);
}
@@ -52,6 +52,17 @@ public class UrlClassLoaderTest {
assertNotNull(UrlClassLoader.build().allowBootstrapResources().get().getResourceAsStream(name));
}
@Test
public void testNonCanonicalPaths() throws IOException {
File root = FileUtil.createTempDirectory("testNonCanonicalPaths", "");
File subDir = createTestDir(root, "dir");
createTestFile(subDir, "a.txt");
UrlClassLoader loader = UrlClassLoader.build().urls(root.toURI().toURL()).get();
assertNotNull(loader.getResourceAsStream("/dir/a.txt"));
assertNotNull(loader.getResourceAsStream("/dir/a.txt/../a.txt"));
}
@Test
public void testConcurrentResourceLoading() throws Exception {
List<String> resourceNames = ContainerUtil.newArrayList();