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
(Cherry-picked from 2146e13787)
This commit is contained in:
Brian Clozel
2018-10-25 14:44:45 +02:00
parent d5f725d503
commit 3b7c0fc1a1
4 changed files with 29 additions and 5 deletions

View File

@@ -96,7 +96,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
*/
protected String toAbsolutePath(String path, ServerWebExchange exchange) {
String requestPath = exchange.getRequest().getURI().getPath();
String absolutePath = StringUtils.applyRelativePath(requestPath, path);
String absolutePath = path.startsWith("/") ? path : StringUtils.applyRelativePath(requestPath, path);
return StringUtils.cleanPath(absolutePath);
}