Fix absolute paths when transforming resources
Prior to this commit, `ResourceTransformerSupport.toAbsolutePath` would call `StringUtils.applyRelativePath` in all cases. But this implementation is prepending the given path even if the relative path starts with `"/"`. This commit skips the entire operation if the given path is absolute, i.e. it starts with `"/"`. Issue: SPR-17432
This commit is contained in:
@@ -94,10 +94,13 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
|
||||
* @return the absolute request path for the given resource path
|
||||
*/
|
||||
protected String toAbsolutePath(String path, HttpServletRequest request) {
|
||||
ResourceUrlProvider urlProvider = findResourceUrlProvider(request);
|
||||
Assert.state(urlProvider != null, "No ResourceUrlProvider");
|
||||
String requestPath = urlProvider.getUrlPathHelper().getRequestUri(request);
|
||||
String absolutePath = StringUtils.applyRelativePath(requestPath, path);
|
||||
String absolutePath = path;
|
||||
if(!path.startsWith("/")) {
|
||||
ResourceUrlProvider urlProvider = findResourceUrlProvider(request);
|
||||
Assert.state(urlProvider != null, "No ResourceUrlProvider");
|
||||
String requestPath = urlProvider.getUrlPathHelper().getRequestUri(request);
|
||||
absolutePath = StringUtils.applyRelativePath(requestPath, path);
|
||||
}
|
||||
return StringUtils.cleanPath(absolutePath);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user