Skip to content

Commit ece8703

Browse files
committed
Merge branch '2.1.x'
Closes spring-projectsgh-17211
2 parents 840f0d7 + 7d59b78 commit ece8703

File tree

2 files changed

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

2 files changed

+30
-3
lines changed

Diff for: spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import java.io.IOException;
2121
import java.lang.ref.SoftReference;
2222
import java.net.MalformedURLException;
23+
import java.net.URI;
2324
import java.net.URL;
2425
import java.net.URLConnection;
25-
import java.net.URLDecoder;
2626
import java.net.URLStreamHandler;
2727
import java.util.Map;
2828
import java.util.concurrent.ConcurrentHashMap;
@@ -302,8 +302,7 @@ private JarFile getRootJarFile(String name) throws IOException {
302302
if (!name.startsWith(FILE_PROTOCOL)) {
303303
throw new IllegalStateException("Not a file URL");
304304
}
305-
String path = name.substring(FILE_PROTOCOL.length());
306-
File file = new File(URLDecoder.decode(path, "UTF-8"));
305+
File file = new File(URI.create(name));
307306
Map<File, JarFile> cache = rootFileCache.get();
308307
JarFile result = (cache != null) ? cache.get(file) : null;
309308
if (result == null) {

Diff for: spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/HandlerTests.java

+28
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,34 @@ void fallbackToJdksJarUrlStreamHandler(@TempDir File tempDir) throws Exception {
165165
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
166166
}
167167

168+
@Test
169+
public void whenJarHasAPlusInItsPathConnectionJarFileMatchesOriginalJarFile() throws Exception {
170+
File testJar = this.temporaryFolder.newFile("t+e+s+t.jar");
171+
TestJarCreator.createTestJar(testJar);
172+
URL url = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/3.dat", this.handler);
173+
JarURLConnection connection = (JarURLConnection) url.openConnection();
174+
try {
175+
assertThat(connection.getJarFile().getRootJarFile().getFile()).isEqualTo(testJar);
176+
}
177+
finally {
178+
connection.getJarFile().close();
179+
}
180+
}
181+
182+
@Test
183+
public void whenJarHasASpaceInItsPathConnectionJarFileMatchesOriginalJarFile() throws Exception {
184+
File testJar = this.temporaryFolder.newFile("t e s t.jar");
185+
TestJarCreator.createTestJar(testJar);
186+
URL url = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/3.dat", this.handler);
187+
JarURLConnection connection = (JarURLConnection) url.openConnection();
188+
try {
189+
assertThat(connection.getJarFile().getRootJarFile().getFile()).isEqualTo(testJar);
190+
}
191+
finally {
192+
connection.getJarFile().close();
193+
}
194+
}
195+
168196
private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec) throws MalformedURLException {
169197
URL standardUrl = new URL(new URL("jar:" + context), spec);
170198
URL customHandlerUrl = new URL(new URL("jar", null, -1, context, this.handler), spec);

0 commit comments

Comments
 (0)