Skip to content

Commit

Permalink
Quote "File.separator" when calling split in KiwiJars#getPathComponents
Browse files Browse the repository at this point in the history
This will make it work on Windows.

Fixes #1201
  • Loading branch information
sleberknight committed Sep 19, 2024
1 parent f2021aa commit e314e2b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/org/kiwiproject/jar/KiwiJars.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;
import java.util.function.Predicate;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import java.util.stream.StreamSupport;

/**
Expand All @@ -36,6 +37,8 @@
@UtilityClass
public class KiwiJars {

private static final String QUOTED_FILE_SEPARATOR = Pattern.quote(File.separator);

/**
* Get the path components of the JAR file path that the given class lives in, or an empty list if the path
* components could not be obtained.
Expand All @@ -54,7 +57,7 @@ public static List<String> getPathComponents(Class<?> classInJar) {
var encodedJarPath = codeSource.getLocation().getPath();
var decodedJarPath = URLDecoder.decode(encodedJarPath, StandardCharsets.UTF_8);

return newArrayList(decodedJarPath.trim().split(File.separator));
return newArrayList(decodedJarPath.trim().split(QUOTED_FILE_SEPARATOR));
} catch (Exception e) {
return logExceptionAndReturnEmptyList(e, classInJar);
}
Expand Down

0 comments on commit e314e2b

Please sign in to comment.