Skip to content

Commit 4161eb1

Browse files
committed
Fix path handling in NestedLocation on Windows
See 4b495ca See gh-37668
1 parent 3eeb1b2 commit 4161eb1

File tree

2 files changed

+11
-3
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader/src

2 files changed

+11
-3
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.loader.net.protocol.nested;
1818

19+
import java.io.File;
1920
import java.net.URI;
2021
import java.net.URL;
2122
import java.nio.file.Path;
@@ -100,9 +101,16 @@ static NestedLocation parse(String path) {
100101
}
101102

102103
private static NestedLocation create(int index, String location) {
103-
String path = location.substring(0, index);
104+
String locationPath = location.substring(0, index);
105+
if (isWindows() && locationPath.startsWith("/")) {
106+
locationPath = locationPath.substring(1, locationPath.length());
107+
}
104108
String nestedEntryName = location.substring(index + 2);
105-
return new NestedLocation((!path.isEmpty()) ? Path.of(path) : null, nestedEntryName);
109+
return new NestedLocation((!locationPath.isEmpty()) ? Path.of(locationPath) : null, nestedEntryName);
110+
}
111+
112+
private static boolean isWindows() {
113+
return File.separatorChar == '\\';
106114
}
107115

108116
static void clearCache() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void fromUriWhenNoSeparatorThrowsExceptiuon() {
120120
void fromUriReturnsNestedLocation() throws Exception {
121121
File file = new File(this.temp, "test.jar");
122122
NestedLocation location = NestedLocation
123-
.fromUri(new URI("nested:" + file.getAbsolutePath() + "/!lib/nested.jar"));
123+
.fromUri(new URI("nested:" + file.getAbsoluteFile().toURI().getPath() + "/!lib/nested.jar"));
124124
assertThat(location.path()).isEqualTo(file.toPath());
125125
assertThat(location.nestedEntryName()).isEqualTo("lib/nested.jar");
126126
}

0 commit comments

Comments
 (0)