Skip to content

Commit 159ef8f

Browse files
committed
Ensure that URL returned from ExplodedArchive.getURL() is encoded
Closes gh-5971
1 parent c808de0 commit 159ef8f

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 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.
@@ -41,6 +41,7 @@
4141
* {@link Archive} implementation backed by an exploded archive directory.
4242
*
4343
* @author Phillip Webb
44+
* @author Andy Wilkinson
4445
*/
4546
public class ExplodedArchive extends Archive {
4647

@@ -116,7 +117,7 @@ private void buildEntries(File file, boolean recursive) {
116117
public URL getUrl() throws MalformedURLException {
117118
FilteredURLStreamHandler handler = this.filtered ? new FilteredURLStreamHandler()
118119
: null;
119-
return new URL("file", "", -1, this.root.toURI().getPath(), handler);
120+
return new URL("file", "", -1, this.root.toURI().toURL().getPath(), handler);
120121
}
121122

122123
@Override

spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 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.
@@ -23,7 +23,6 @@
2323
import java.io.OutputStream;
2424
import java.net.URL;
2525
import java.net.URLClassLoader;
26-
import java.net.URLDecoder;
2726
import java.util.Enumeration;
2827
import java.util.HashMap;
2928
import java.util.Map;
@@ -38,6 +37,7 @@
3837
import org.springframework.boot.loader.TestJarCreator;
3938
import org.springframework.boot.loader.archive.Archive.Entry;
4039
import org.springframework.boot.loader.util.AsciiBytes;
40+
import org.springframework.util.StringUtils;
4141

4242
import static org.hamcrest.Matchers.equalTo;
4343
import static org.hamcrest.Matchers.greaterThan;
@@ -50,6 +50,7 @@
5050
*
5151
* @author Phillip Webb
5252
* @author Dave Syer
53+
* @author Andy Wilkinson
5354
*/
5455
public class ExplodedArchiveTests {
5556

@@ -62,10 +63,20 @@ public class ExplodedArchiveTests {
6263

6364
@Before
6465
public void setup() throws Exception {
66+
createArchive();
67+
}
68+
69+
private void createArchive() throws Exception {
70+
createArchive(null);
71+
}
72+
73+
private void createArchive(String folderName) throws Exception {
6574
File file = this.temporaryFolder.newFile();
6675
TestJarCreator.createTestJar(file);
6776

68-
this.rootFolder = this.temporaryFolder.newFolder();
77+
this.rootFolder = StringUtils.hasText(folderName)
78+
? this.temporaryFolder.newFolder(folderName)
79+
: this.temporaryFolder.newFolder();
6980
JarFile jarFile = new JarFile(file);
7081
Enumeration<JarEntry> entries = jarFile.entries();
7182
while (entries.hasMoreElements()) {
@@ -107,9 +118,13 @@ public void getEntries() throws Exception {
107118

108119
@Test
109120
public void getUrl() throws Exception {
110-
URL url = this.archive.getUrl();
111-
assertThat(new File(URLDecoder.decode(url.getFile(), "UTF-8")),
112-
equalTo(this.rootFolder));
121+
assertThat(this.archive.getUrl(), equalTo(this.rootFolder.toURI().toURL()));
122+
}
123+
124+
@Test
125+
public void getUrlWithSpaceInPath() throws Exception {
126+
createArchive("spaces in the name");
127+
assertThat(this.archive.getUrl(), equalTo(this.rootFolder.toURI().toURL()));
113128
}
114129

115130
@Test

0 commit comments

Comments
 (0)