Fix path handling in NestedLocation on Windows

See 4b495ca
See gh-37668
This commit is contained in:
Andy Wilkinson
2023-10-20 09:15:54 +01:00
parent 3eeb1b2849
commit 4161eb1853
2 changed files with 11 additions and 3 deletions

View File

@@ -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() {