Skip to content

Commit a457638

Browse files
committed
Polish 'Decode URL content before passing it to NestedLocation.parse'
See gh-39675' Closes gh-39675'
1 parent 06569e7 commit a457638

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

+24-7
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ void getPermissionReturnsFilePermission() throws Exception {
121121
@Test
122122
void getInputStreamReturnsContentOfNestedJar() throws Exception {
123123
NestedUrlConnection connection = new NestedUrlConnection(this.url);
124-
try (InputStream actual = connection.getInputStream()) {
125-
try (ZipContent zipContent = ZipContent.open(this.jarFile.toPath())) {
126-
try (InputStream expected = zipContent.getEntry("nested.jar").openContent().asInputStream()) {
127-
assertThat(actual).hasSameContentAs(expected);
128-
}
129-
}
130-
}
124+
assertHasSameContentAsNestedJar(connection);
131125
}
132126

133127
@Test
@@ -163,6 +157,29 @@ void getLastModifiedHeaderReturnsFileModifiedTime() throws IOException {
163157
}
164158
}
165159

160+
@Test
161+
void createDecodesUrlPath() throws Exception {
162+
File withSpace = new File(this.temp, "te st");
163+
withSpace.mkdirs();
164+
this.jarFile = new File(withSpace, "test.jar");
165+
TestJar.create(this.jarFile);
166+
this.url = new URL("nested:" + this.jarFile.toURI().getRawPath() + "/!nested.jar");
167+
assertThat(this.url.toString()).contains("%20");
168+
NestedUrlConnection connection = new NestedUrlConnection(this.url);
169+
assertHasSameContentAsNestedJar(connection);
170+
assertThat(connection.getLastModified()).isEqualTo(this.jarFile.lastModified());
171+
}
172+
173+
private void assertHasSameContentAsNestedJar(NestedUrlConnection connection) throws IOException {
174+
try (InputStream actual = connection.getInputStream()) {
175+
try (ZipContent zipContent = ZipContent.open(this.jarFile.toPath())) {
176+
try (InputStream expected = zipContent.getEntry("nested.jar").openContent().asInputStream()) {
177+
assertThat(actual).hasSameContentAs(expected);
178+
}
179+
}
180+
}
181+
}
182+
166183
private long withoutNanos(long epochMilli) {
167184
return Instant.ofEpochMilli(epochMilli).with(ChronoField.NANO_OF_SECOND, 0).toEpochMilli();
168185
}

0 commit comments

Comments
 (0)