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 {
|
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) {
|
IdeApplicationLauncher(ApplicationBuilder applicationBuilder) {
|
||||||
super(applicationBuilder);
|
super(applicationBuilder);
|
||||||
|
@ -109,7 +109,7 @@ public abstract class AbstractEmbeddedServletContainerFactory
|
|||||||
private boolean isStaticResourceJar(URL url) {
|
private boolean isStaticResourceJar(URL url) {
|
||||||
try {
|
try {
|
||||||
if ("file".equals(url.getProtocol())) {
|
if ("file".equals(url.getProtocol())) {
|
||||||
File file = new File(getDecodedFile(url));
|
File file = new File(url.toURI());
|
||||||
return (file.isDirectory()
|
return (file.isDirectory()
|
||||||
&& new File(file, "META-INF/resources").isDirectory())
|
&& new File(file, "META-INF/resources").isDirectory())
|
||||||
|| isResourcesJar(file);
|
|| isResourcesJar(file);
|
||||||
@ -122,12 +122,20 @@ public abstract class AbstractEmbeddedServletContainerFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException(ex);
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
return false;
|
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) {
|
protected final String getDecodedFile(URL url) {
|
||||||
try {
|
try {
|
||||||
return URLDecoder.decode(url.getFile(), "UTF-8");
|
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())) {
|
if ("file".equals(url.getProtocol())) {
|
||||||
File file = new File(getDecodedFile(url));
|
File file = new File(url.toURI());
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
return Resource.newResource("jar:" + url + "!/META-INF/resources");
|
return Resource.newResource("jar:" + url + "!/META-INF/resources");
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.boot.context.embedded.tomcat;
|
package org.springframework.boot.context.embedded.tomcat;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.naming.directory.DirContext;
|
import javax.naming.directory.DirContext;
|
||||||
@ -49,31 +49,27 @@ abstract class TomcatResources {
|
|||||||
|
|
||||||
void addResourceJars(List<URL> resourceJarUrls) {
|
void addResourceJars(List<URL> resourceJarUrls) {
|
||||||
for (URL url : resourceJarUrls) {
|
for (URL url : resourceJarUrls) {
|
||||||
String file = getDecodedFile(url);
|
try {
|
||||||
if (file.endsWith(".jar") || file.endsWith(".jar!/")) {
|
String path = url.getPath();
|
||||||
String jar = url.toString();
|
if (path.endsWith(".jar") || path.endsWith(".jar!/")) {
|
||||||
if (!jar.startsWith("jar:")) {
|
String jar = url.toString();
|
||||||
// A jar file in the file system. Convert to Jar URL.
|
if (!jar.startsWith("jar:")) {
|
||||||
jar = "jar:" + jar + "!/";
|
// A jar file in the file system. Convert to Jar URL.
|
||||||
|
jar = "jar:" + jar + "!/";
|
||||||
|
}
|
||||||
|
addJar(jar);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addDir(new File(url.toURI()).getAbsolutePath(), url);
|
||||||
}
|
}
|
||||||
addJar(jar);
|
|
||||||
}
|
}
|
||||||
else {
|
catch (URISyntaxException ex) {
|
||||||
addDir(file, url);
|
throw new IllegalStateException(
|
||||||
|
"Failed to create File from URL '" + url + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDecodedFile(URL url) {
|
|
||||||
try {
|
|
||||||
return URLDecoder.decode(url.getFile(), "UTF-8");
|
|
||||||
}
|
|
||||||
catch (UnsupportedEncodingException ex) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Failed to decode '" + url.getFile() + "' using UTF-8");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Context getContext() {
|
protected final Context getContext() {
|
||||||
return this.context;
|
return this.context;
|
||||||
}
|
}
|
||||||
|
@ -494,18 +494,18 @@ public class UndertowEmbeddedServletContainerFactory
|
|||||||
resourceManagers.add(rootResourceManager);
|
resourceManagers.add(rootResourceManager);
|
||||||
for (URL url : metaInfResourceUrls) {
|
for (URL url : metaInfResourceUrls) {
|
||||||
if ("file".equals(url.getProtocol())) {
|
if ("file".equals(url.getProtocol())) {
|
||||||
File file = new File(getDecodedFile(url));
|
try {
|
||||||
if (file.isFile()) {
|
File file = new File(url.toURI());
|
||||||
try {
|
if (file.isFile()) {
|
||||||
resourceJarUrls.add(new URL("jar:" + url + "!/"));
|
resourceJarUrls.add(new URL("jar:" + url + "!/"));
|
||||||
}
|
}
|
||||||
catch (MalformedURLException ex) {
|
else {
|
||||||
throw new RuntimeException(ex);
|
resourceManagers.add(new FileResourceManager(
|
||||||
|
new File(file, "META-INF/resources"), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
catch (Exception ex) {
|
||||||
resourceManagers.add(new FileResourceManager(
|
throw new RuntimeException(ex);
|
||||||
new File(file, "META-INF/resources"), 0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user