mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Leverage ResourceHandlerUtils in ScriptTemplateView
This commit apply extra checks to ScriptTemplateView resource handling with ResourceHandlerUtils, consistently with what is done with static resource handling. Closes gh-36459
This commit is contained in:
+20
-4
@@ -47,6 +47,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.resource.ResourceHandlerUtils;
|
||||
import org.springframework.web.reactive.result.view.AbstractUrlBasedView;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
@@ -306,11 +307,26 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
|
||||
|
||||
@Nullable
|
||||
protected Resource getResource(String location) {
|
||||
if (this.resourceLoaderPaths != null) {
|
||||
String normalizedLocation = ResourceHandlerUtils.normalizeInputPath(location);
|
||||
if (this.resourceLoaderPaths != null && !ResourceHandlerUtils.shouldIgnoreInputPath(normalizedLocation)) {
|
||||
ApplicationContext context = obtainApplicationContext();
|
||||
for (String path : this.resourceLoaderPaths) {
|
||||
Resource resource = obtainApplicationContext().getResource(path + location);
|
||||
if (resource.exists()) {
|
||||
return resource;
|
||||
Resource resource = context.getResource(path + normalizedLocation);
|
||||
try {
|
||||
if (resource.exists() && ResourceHandlerUtils.isResourceUnderLocation(context.getResource(path), resource)) {
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
String error = "Skip location [" + normalizedLocation + "] due to error";
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(error, ex);
|
||||
}
|
||||
else {
|
||||
logger.debug(error + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-4
@@ -51,6 +51,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.resource.ResourceHandlerUtils;
|
||||
import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
import org.springframework.web.servlet.view.AbstractUrlBasedView;
|
||||
|
||||
@@ -351,11 +352,26 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
|
||||
|
||||
@Nullable
|
||||
protected Resource getResource(String location) {
|
||||
if (this.resourceLoaderPaths != null) {
|
||||
String normalizedLocation = ResourceHandlerUtils.normalizeInputPath(location);
|
||||
if (this.resourceLoaderPaths != null && !ResourceHandlerUtils.shouldIgnoreInputPath(normalizedLocation)) {
|
||||
ApplicationContext context = obtainApplicationContext();
|
||||
for (String path : this.resourceLoaderPaths) {
|
||||
Resource resource = obtainApplicationContext().getResource(path + location);
|
||||
if (resource.exists()) {
|
||||
return resource;
|
||||
Resource resource = context.getResource(path + normalizedLocation);
|
||||
try {
|
||||
if (resource.exists() && ResourceHandlerUtils.isResourceUnderLocation(context.getResource(path), resource)) {
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
String error = "Skip location [" + normalizedLocation + "] due to error";
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(error, ex);
|
||||
}
|
||||
else {
|
||||
logger.debug(error + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user