Skip to content

Commit 213bcd1

Browse files
committed
Fix getResource("") failing to return valid resource
Fixes #187
1 parent 0a9644a commit 213bcd1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

forge/src/main/java/org/embeddedt/modernfix/forge/classloading/ModernFixResourceFinder.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,20 @@ private static Iterable<Path> getRootPathForLocator(IModLocator locator, ModFile
9292
}
9393

9494
public static Enumeration<URL> findAllURLsForResource(String input) {
95-
// CachedResourcePath normalizes already
95+
// CachedResourcePath normalizes already but we need to strip trailing slash if any
96+
// TODO move logic to FileUtil.normalize()
97+
int lastIndex = input.length();
98+
boolean strip = false;
99+
while(lastIndex > 1) {
100+
char c = input.charAt(lastIndex - 1);
101+
if (c == '/' || c == '\\') {
102+
lastIndex--;
103+
strip = true;
104+
} else
105+
break;
106+
}
107+
if(strip)
108+
input = input.substring(0, lastIndex);
96109
Collection<String> urlList = urlsForClass.get(new CachedResourcePath(input));
97110
if(!urlList.isEmpty()) {
98111
String pathInput = FileUtil.normalize(input);

0 commit comments

Comments
 (0)