Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote "File.separator" when calling split in KiwiJars#getPathComponents #1202

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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