mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Only use jar shortcut for matching URLs
Update JAR `Handler` logic so that the existing `jarFile` is only used if the requested URL starts with the same path. Prior to this commit it was possible to construct a URL with another URL as context. This could mean that the `handler` was shared and the already resolved `jarFile` contained in the handler wasn't necessarily suitable. Fixes gh-12483
This commit is contained in:
parent
e40acf2447
commit
e975dbe3f0
@ -92,7 +92,8 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
if (this.jarFile != null) {
|
||||
if (this.jarFile != null
|
||||
&& url.toString().startsWith(this.jarFile.getUrl().toString())) {
|
||||
return JarURLConnection.get(url, this.jarFile);
|
||||
}
|
||||
try {
|
||||
|
@ -485,4 +485,24 @@ public class JarFileTests {
|
||||
assertThat(temp.delete()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUrlFromStringWithContextWhenNotFound() throws Exception {
|
||||
// gh-12483
|
||||
JarURLConnection.setUseFastExceptions(true);
|
||||
try {
|
||||
JarFile.registerUrlProtocolHandler();
|
||||
JarFile nested = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL context = nested.getUrl();
|
||||
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat")
|
||||
.openConnection().getInputStream().close();
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
new URL(context, "jar:" + this.rootJarFile.toURI() + "!/no.dat")
|
||||
.openConnection().getInputStream().close();
|
||||
}
|
||||
finally {
|
||||
JarURLConnection.setUseFastExceptions(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user