Browse Source

Fix path handling in NestedLocation on Windows

See 4b495ca
See gh-37668
pull/37973/head
Andy Wilkinson 2 years ago
parent
commit
4161eb1853
  1. 12
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/nested/NestedLocation.java
  2. 2
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/net/protocol/nested/NestedLocationTests.java

12
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/nested/NestedLocation.java

@ -16,6 +16,7 @@ @@ -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) { @@ -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() {

2
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/net/protocol/nested/NestedLocationTests.java

@ -120,7 +120,7 @@ class NestedLocationTests { @@ -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");
}

Loading…
Cancel
Save