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:
@@ -41,7 +41,7 @@ public class ResourceTransformerSupportTests {
|
||||
|
||||
private TestResourceTransformerSupport transformer;
|
||||
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
|
||||
|
||||
@Before
|
||||
@@ -98,6 +98,17 @@ public class ResourceTransformerSupportTests {
|
||||
assertEquals("../bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toAbsolutePath() {
|
||||
String absolute = this.transformer.toAbsolutePath("img/image.png",
|
||||
new MockHttpServletRequest("GET", "/resources/style.css"));
|
||||
assertEquals("/resources/img/image.png", absolute);
|
||||
|
||||
absolute = this.transformer.toAbsolutePath("/img/image.png",
|
||||
new MockHttpServletRequest("GET", "/resources/style.css"));
|
||||
assertEquals("/img/image.png", absolute);
|
||||
}
|
||||
|
||||
private Resource getResource(String filePath) {
|
||||
return new ClassPathResource("test/" + filePath, getClass());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user