Skip to content

Commit d13c006

Browse files
committed
Merge pull request #39675' from slovi
* pr/39675: Polish 'Decode URL content before passing it to NestedLocation.parse' Decode URL content before passing it to NestedLocation.parse Closes gh-39675
2 parents 428ddb7 + a457638 commit d13c006

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

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

+3-2
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.
@@ -38,6 +38,7 @@
3838
import java.util.Map;
3939
import java.util.Map.Entry;
4040

41+
import org.springframework.boot.loader.net.util.UrlDecoder;
4142
import org.springframework.boot.loader.ref.Cleaner;
4243

4344
/**
@@ -76,7 +77,7 @@ class NestedUrlConnection extends URLConnection {
7677

7778
private NestedLocation parseNestedLocation(URL url) throws MalformedURLException {
7879
try {
79-
return NestedLocation.parse(url.getPath());
80+
return NestedLocation.parse(UrlDecoder.decode(url.getPath()));
8081
}
8182
catch (IllegalArgumentException ex) {
8283
throw new MalformedURLException(ex.getMessage());

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)