Fix path handling in NestedLocation on Windows
See 4b495ca
See gh-37668
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.loader.net.protocol.nested;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
@@ -100,9 +101,16 @@ public record NestedLocation(Path path, String nestedEntryName) {
|
||||
}
|
||||
|
||||
private static NestedLocation create(int index, String location) {
|
||||
String path = location.substring(0, index);
|
||||
String locationPath = location.substring(0, index);
|
||||
if (isWindows() && locationPath.startsWith("/")) {
|
||||
locationPath = locationPath.substring(1, locationPath.length());
|
||||
}
|
||||
String nestedEntryName = location.substring(index + 2);
|
||||
return new NestedLocation((!path.isEmpty()) ? Path.of(path) : null, nestedEntryName);
|
||||
return new NestedLocation((!locationPath.isEmpty()) ? Path.of(locationPath) : null, nestedEntryName);
|
||||
}
|
||||
|
||||
private static boolean isWindows() {
|
||||
return File.separatorChar == '\\';
|
||||
}
|
||||
|
||||
static void clearCache() {
|
||||
|
||||
@@ -120,7 +120,7 @@ class NestedLocationTests {
|
||||
void fromUriReturnsNestedLocation() throws Exception {
|
||||
File file = new File(this.temp, "test.jar");
|
||||
NestedLocation location = NestedLocation
|
||||
.fromUri(new URI("nested:" + file.getAbsolutePath() + "/!lib/nested.jar"));
|
||||
.fromUri(new URI("nested:" + file.getAbsoluteFile().toURI().getPath() + "/!lib/nested.jar"));
|
||||
assertThat(location.path()).isEqualTo(file.toPath());
|
||||
assertThat(location.nestedEntryName()).isEqualTo("lib/nested.jar");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user