parent
37243f44e8
commit
59ec871e76
|
@ -65,7 +65,8 @@ public abstract class ResourceHandlerUtils {
|
|||
else {
|
||||
path = location.getURL().getPath();
|
||||
}
|
||||
assertLocationPath(path);
|
||||
Assert.isTrue(path.endsWith(FOLDER_SEPARATOR) || path.endsWith(WINDOWS_FOLDER_SEPARATOR),
|
||||
"Resource location does not end with slash: " + path);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
|
@ -73,12 +74,18 @@ public abstract class ResourceHandlerUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Assert the given location path is a directory and ends on slash.
|
||||
* Check if the given static resource location path ends with a trailing
|
||||
* slash, and append it if necessary.
|
||||
* @param path the location path
|
||||
* @return the resulting path to use
|
||||
*/
|
||||
public static void assertLocationPath(@Nullable String path) {
|
||||
Assert.notNull(path, "Resource location path must not be null");
|
||||
Assert.isTrue(path.endsWith(FOLDER_SEPARATOR) || path.endsWith(WINDOWS_FOLDER_SEPARATOR),
|
||||
"Resource location does not end with slash: " + path);
|
||||
public static String initLocationPath(String path) {
|
||||
String separator = (path.contains(FOLDER_SEPARATOR) ? FOLDER_SEPARATOR : WINDOWS_FOLDER_SEPARATOR);
|
||||
if (!path.endsWith(separator)) {
|
||||
path = path.concat(separator);
|
||||
logger.warn("Appended trailing slash to static resource location: " + path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -379,7 +379,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
|||
Assert.isTrue(CollectionUtils.isEmpty(this.locationResources), "Please set " +
|
||||
"either Resource-based \"locations\" or String-based \"locationValues\", but not both.");
|
||||
for (String location : this.locationValues) {
|
||||
ResourceHandlerUtils.assertLocationPath(location);
|
||||
location = ResourceHandlerUtils.initLocationPath(location);
|
||||
result.add(this.resourceLoader.getResource(location));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,8 @@ public abstract class ResourceHandlerUtils {
|
|||
else {
|
||||
path = location.getURL().getPath();
|
||||
}
|
||||
assertLocationPath(path);
|
||||
Assert.isTrue(path.endsWith(FOLDER_SEPARATOR) || path.endsWith(WINDOWS_FOLDER_SEPARATOR),
|
||||
"Resource location does not end with slash: " + path);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
|
@ -73,12 +74,18 @@ public abstract class ResourceHandlerUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Assert the given location path is a directory and ends on slash.
|
||||
* Check if the given static resource location path ends with a trailing
|
||||
* slash, and append it if necessary.
|
||||
* @param path the location path
|
||||
* @return the resulting path to use
|
||||
*/
|
||||
public static void assertLocationPath(@Nullable String path) {
|
||||
Assert.notNull(path, "Resource location path must not be null");
|
||||
Assert.isTrue(path.endsWith(FOLDER_SEPARATOR) || path.endsWith(WINDOWS_FOLDER_SEPARATOR),
|
||||
"Resource location does not end with slash: " + path);
|
||||
public static String initLocationPath(String path) {
|
||||
String separator = (path.contains(FOLDER_SEPARATOR) ? FOLDER_SEPARATOR : WINDOWS_FOLDER_SEPARATOR);
|
||||
if (!path.endsWith(separator)) {
|
||||
path = path.concat(separator);
|
||||
logger.warn("Appended trailing slash to static resource location: " + path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -496,7 +496,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
|||
charset = Charset.forName(value);
|
||||
location = location.substring(endIndex + 1);
|
||||
}
|
||||
ResourceHandlerUtils.assertLocationPath(location);
|
||||
location = ResourceHandlerUtils.initLocationPath(location);
|
||||
Resource resource = applicationContext.getResource(location);
|
||||
if (location.equals("/") && !(resource instanceof ServletContextResource)) {
|
||||
throw new IllegalStateException(
|
||||
|
|
Loading…
Reference in New Issue