Skip to content

Commit

Permalink
Fix jar uri parsing in CloseablePath
Browse files Browse the repository at this point in the history
Jar uris follow the format[1]:

```
jar:<url>!/[<entry>]
```

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
  • Loading branch information
mpkorstanje committed Dec 17, 2023
1 parent 8f5fbd0 commit e81b50f
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () -> {
};
Expand All @@ -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:<url>!/[<entry>]
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);
}
Expand Down

0 comments on commit e81b50f

Please sign in to comment.