From e81b50f1b67d45d1625b449c7c4c21153414ad5d Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 17 Dec 2023 10:19:50 +0100 Subject: [PATCH] Fix jar uri parsing in CloseablePath Jar uris follow the format[1]: ``` jar:!/[] ``` So splitting should be done on the last `!/` rather than the first. Fixes: #1724 for Spring Boot 3.2 and later. 1. https://docs.oracle.com/javase/8/docs/api/java/net/JarURLConnection.html --- .../org/junit/platform/commons/util/CloseablePath.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java index 3f7af1ddd407..a7303b6ba775 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java @@ -35,7 +35,7 @@ final class CloseablePath implements Closeable { private static final String FILE_URI_SCHEME = "file"; static final String JAR_URI_SCHEME = "jar"; private static final String JAR_FILE_EXTENSION = ".jar"; - private static final String JAR_URI_SEPARATOR = "!"; + private static final String JAR_URI_SEPARATOR = "!/"; private static final Closeable NULL_CLOSEABLE = () -> { }; @@ -53,9 +53,11 @@ static CloseablePath create(URI uri) throws URISyntaxException { static CloseablePath create(URI uri, FileSystemProvider fileSystemProvider) throws URISyntaxException { if (JAR_URI_SCHEME.equals(uri.getScheme())) { - String[] parts = uri.toString().split(JAR_URI_SEPARATOR); - String jarUri = parts[0]; - String jarEntry = parts[1]; + // Parsing: jar:!/[] + String uriString = uri.toString(); + int lastJarUriSeparator = uriString.lastIndexOf(JAR_URI_SEPARATOR); + String jarUri = uriString.substring(0, lastJarUriSeparator); + String jarEntry = uriString.substring(lastJarUriSeparator + 1); return createForJarFileSystem(new URI(jarUri), fileSystem -> fileSystem.getPath(jarEntry), fileSystemProvider); }