mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Fix handling of static resource jar paths containing a +
Closes gh-12942
This commit is contained in:
parent
08bc306a61
commit
a29a70d2f4
@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
class IdeApplicationLauncher extends AbstractApplicationLauncher {
|
||||
|
||||
private final File exploded = new File("target/ide application");
|
||||
private final File exploded = new File("target/the+ide application");
|
||||
|
||||
IdeApplicationLauncher(ApplicationBuilder applicationBuilder) {
|
||||
super(applicationBuilder);
|
||||
|
@ -109,7 +109,7 @@ public abstract class AbstractEmbeddedServletContainerFactory
|
||||
private boolean isStaticResourceJar(URL url) {
|
||||
try {
|
||||
if ("file".equals(url.getProtocol())) {
|
||||
File file = new File(getDecodedFile(url));
|
||||
File file = new File(url.toURI());
|
||||
return (file.isDirectory()
|
||||
&& new File(file, "META-INF/resources").isDirectory())
|
||||
|| isResourcesJar(file);
|
||||
@ -122,12 +122,20 @@ public abstract class AbstractEmbeddedServletContainerFactory
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given {@code url} into a decoded file path.
|
||||
*
|
||||
* @param url the url to convert
|
||||
* @return the file path
|
||||
* @deprecated Since 1.5.13 in favor of {@link File#File(java.net.URI)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected final String getDecodedFile(URL url) {
|
||||
try {
|
||||
return URLDecoder.decode(url.getFile(), "UTF-8");
|
||||
|
@ -431,9 +431,9 @@ public class JettyEmbeddedServletContainerFactory
|
||||
}
|
||||
}
|
||||
|
||||
private Resource createResource(URL url) throws IOException {
|
||||
private Resource createResource(URL url) throws Exception {
|
||||
if ("file".equals(url.getProtocol())) {
|
||||
File file = new File(getDecodedFile(url));
|
||||
File file = new File(url.toURI());
|
||||
if (file.isFile()) {
|
||||
return Resource.newResource("jar:" + url + "!/META-INF/resources");
|
||||
}
|
||||
|
@ -16,11 +16,11 @@
|
||||
|
||||
package org.springframework.boot.context.embedded.tomcat;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.directory.DirContext;
|
||||
@ -49,8 +49,9 @@ abstract class TomcatResources {
|
||||
|
||||
void addResourceJars(List<URL> resourceJarUrls) {
|
||||
for (URL url : resourceJarUrls) {
|
||||
String file = getDecodedFile(url);
|
||||
if (file.endsWith(".jar") || file.endsWith(".jar!/")) {
|
||||
try {
|
||||
String path = url.getPath();
|
||||
if (path.endsWith(".jar") || path.endsWith(".jar!/")) {
|
||||
String jar = url.toString();
|
||||
if (!jar.startsWith("jar:")) {
|
||||
// A jar file in the file system. Convert to Jar URL.
|
||||
@ -59,18 +60,13 @@ abstract class TomcatResources {
|
||||
addJar(jar);
|
||||
}
|
||||
else {
|
||||
addDir(file, url);
|
||||
addDir(new File(url.toURI()).getAbsolutePath(), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getDecodedFile(URL url) {
|
||||
try {
|
||||
return URLDecoder.decode(url.getFile(), "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to decode '" + url.getFile() + "' using UTF-8");
|
||||
"Failed to create File from URL '" + url + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -494,20 +494,20 @@ public class UndertowEmbeddedServletContainerFactory
|
||||
resourceManagers.add(rootResourceManager);
|
||||
for (URL url : metaInfResourceUrls) {
|
||||
if ("file".equals(url.getProtocol())) {
|
||||
File file = new File(getDecodedFile(url));
|
||||
if (file.isFile()) {
|
||||
try {
|
||||
File file = new File(url.toURI());
|
||||
if (file.isFile()) {
|
||||
resourceJarUrls.add(new URL("jar:" + url + "!/"));
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
resourceManagers.add(new FileResourceManager(
|
||||
new File(file, "META-INF/resources"), 0));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
resourceJarUrls.add(url);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user