Skip to content

Commit

Permalink
More UNC path fixes (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Nov 17, 2022
1 parent da7bf21 commit 4ad2340
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
10 changes: 7 additions & 3 deletions src/main/java/io/github/classgraph/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,13 @@ private static Object normalizeClasspathEntry(final Object classpathEntryObj) th
// Last-ditch effort -- try to convert String to Path
if (classpathEntryObjNormalized instanceof String) {
try {
classpathEntryObjNormalized = Paths.get((String) classpathEntryObjNormalized);
} catch (final InvalidPathException e) {
throw new IOException("Malformed path: " + classpathEntryObj + " : " + e);
classpathEntryObjNormalized = new File((String) classpathEntryObjNormalized).toPath();
} catch (final Exception e) {
try {
classpathEntryObjNormalized = Paths.get((String) classpathEntryObjNormalized);
} catch (final InvalidPathException e2) {
throw new IOException("Malformed path: " + classpathEntryObj + " : " + e2);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public boolean addClasspathEntry(final Object pathElement, final ClassLoader cla
}
pathElementURL = null;
}
if (pathElement instanceof URL || pathElement instanceof URI || pathElement instanceof File
if (pathElementURL != null || pathElement instanceof URI || pathElement instanceof File
|| pathElement instanceof Path) {
if (!filter(pathElementURL, pathElementStr)) {
if (log != null) {
Expand All @@ -326,7 +326,7 @@ public boolean addClasspathEntry(final Object pathElement, final ClassLoader cla
// for URI and Path objects, convert to URL; for File objects, use the toString result (the path)
final Object classpathElementObj;
classpathElementObj = pathElement instanceof File ? pathElementStr
: pathElement instanceof Path || pathElement instanceof URI ? pathElementURL : pathElement;
: pathElementURL != null ? pathElementURL : pathElement;
if (addClasspathEntry(classpathElementObj, pathElementStr, classLoader, scanSpec)) {
if (log != null) {
log.log("Found classpath element: " + pathElementStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ public static String resolve(final String resolveBasePath, final String relative
// Strip off "file:" prefix from relative path
matchedPrefix = true;
startIdx += 5;
while (startIdx < relativePath.length() - 1 && relativePath.charAt(startIdx) == '/'
&& relativePath.charAt(startIdx + 1) == '/') {
// Strip off all but one '/' after "file:"
startIdx++;
}
isFileOrJarURL = true;
} else {
// Preserve the number of slashes on custom URL schemes (#420)
Expand All @@ -265,16 +260,6 @@ public static String resolve(final String resolveBasePath, final String relative
}
} while (matchedPrefix);

if (isFileOrJarURL) {
if (relativePath.startsWith("///", startIdx)) {
// "file:///" or "jar:///" URL
startIdx += 2;
} else if (relativePath.startsWith("//", startIdx)) {
// "file://" or "jar://" URL
startIdx += 1;
}
}

// Handle Windows paths starting with a drive designation as an absolute path
if (WINDOWS) {
if (relativePath.startsWith("//", startIdx) || relativePath.startsWith("\\\\", startIdx)) {
Expand Down

0 comments on commit 4ad2340

Please sign in to comment.