Adapt Windows path handling fix to deal with Jetty

Update `NestedLocation` to deal with the fact that Jetty attempts
to fix URLs.

See gh-40549
This commit is contained in:
Phillip Webb 2024-05-08 17:12:46 -07:00
parent 7708ec7592
commit 8457fc333f
1 changed files with 13 additions and 5 deletions

View File

@ -107,11 +107,7 @@ public record NestedLocation(Path path, String nestedEntryName) {
private static Path asPath(String locationPath) {
return pathCache.computeIfAbsent(locationPath, (key) -> {
if (isWindows() && locationPath.length() > 2 && locationPath.charAt(2) == ':') {
// Use the same logic as Java's internal WindowsUriSupport class
return Path.of(locationPath.substring(1));
}
return Path.of(locationPath);
return Path.of((!isWindows()) ? locationPath : fixWindowsLocationPath(locationPath));
});
}
@ -119,6 +115,18 @@ public record NestedLocation(Path path, String nestedEntryName) {
return File.separatorChar == '\\';
}
private static String fixWindowsLocationPath(String locationPath) {
// Same logic as Java's internal WindowsUriSupport class
if (locationPath.length() > 2 && locationPath.charAt(2) == ':') {
return locationPath.substring(1);
}
// Deal with Jetty's org.eclipse.jetty.util.URIUtil#correctURI(URI)
if (locationPath.startsWith("///") && locationPath.charAt(4) == ':') {
return locationPath.substring(3);
}
return locationPath;
}
static void clearCache() {
locationCache.clear();
pathCache.clear();