Skip to content

Commit f42b442

Browse files
committed
Fix handling of encoded URLs in Class-Path manifest attribute
Fixes gh-18410
1 parent 2423275 commit f42b442

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.net.MalformedURLException;
2323
import java.net.URL;
2424
import java.net.URLClassLoader;
25+
import java.net.URLDecoder;
2526
import java.util.ArrayList;
2627
import java.util.Collection;
2728
import java.util.Collections;
@@ -156,7 +157,13 @@ private static List<URL> getUrlsFromManifestClassPathAttribute(URL jarUrl, JarFi
156157
urls.add(referenced);
157158
}
158159
else {
159-
nonExistentEntries.add(referenced);
160+
referenced = new URL(jarUrl, URLDecoder.decode(entry, "UTF-8"));
161+
if (new File(referenced.getFile()).exists()) {
162+
urls.add(referenced);
163+
}
164+
else {
165+
nonExistentEntries.add(referenced);
166+
}
160167
}
161168
}
162169
catch (MalformedURLException ex) {

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,17 @@ public void urlsFromJarClassPathAreConsidered() throws Exception {
8282
File relative = this.temporaryFolder.newFolder();
8383
URL absoluteUrl = this.temporaryFolder.newFolder().toURI().toURL();
8484
File jarWithClassPath = makeJarFileWithUrlsInManifestClassPath("project-core/target/classes/",
85-
"project-web/target/classes/", "does-not-exist/target/classes", relative.getName() + "/", absoluteUrl);
85+
"project-web/target/classes/", "project%20space/target/classes/", "does-not-exist/target/classes/",
86+
relative.getName() + "/", absoluteUrl);
8687
new File(jarWithClassPath.getParentFile(), "project-core/target/classes").mkdirs();
8788
new File(jarWithClassPath.getParentFile(), "project-web/target/classes").mkdirs();
89+
new File(jarWithClassPath.getParentFile(), "project space/target/classes").mkdirs();
8890
ChangeableUrls urls = ChangeableUrls.fromClassLoader(
8991
new URLClassLoader(new URL[] { jarWithClassPath.toURI().toURL(), makeJarFileWithNoManifest() }));
9092
assertThat(urls.toList()).containsExactly(
9193
new URL(jarWithClassPath.toURI().toURL(), "project-core/target/classes/"),
92-
new URL(jarWithClassPath.toURI().toURL(), "project-web/target/classes/"), relative.toURI().toURL(),
94+
new URL(jarWithClassPath.toURI().toURL(), "project-web/target/classes/"),
95+
new URL(jarWithClassPath.toURI().toURL(), "project space/target/classes/"), relative.toURI().toURL(),
9396
absoluteUrl);
9497
}
9598

0 commit comments

Comments
 (0)