Allow file locations for resource handling
Prior to this change, location checks for serving resources would append `/` to the location path it didn't already have one. This commit makes sure not to append a `/` if the provided location is actually a file. Issue: SPR-12747
This commit is contained in:
@@ -315,6 +315,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H
|
|||||||
resourcePath = resource.getURL().getPath();
|
resourcePath = resource.getURL().getPath();
|
||||||
locationPath = location.getURL().getPath();
|
locationPath = location.getURL().getPath();
|
||||||
}
|
}
|
||||||
|
if(locationPath.equals(resourcePath)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
locationPath = (locationPath.endsWith("/") ||
|
locationPath = (locationPath.endsWith("/") ||
|
||||||
!StringUtils.hasLength(locationPath) ? locationPath : locationPath + "/");
|
!StringUtils.hasLength(locationPath) ? locationPath : locationPath + "/");
|
||||||
if (!resourcePath.startsWith(locationPath)) {
|
if (!resourcePath.startsWith(locationPath)) {
|
||||||
|
|||||||
@@ -280,6 +280,22 @@ public class ResourceHttpRequestHandlerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// SPR-12747
|
||||||
|
@Test
|
||||||
|
public void getResourceWithResourceLocation() throws Exception {
|
||||||
|
List<Resource> resourcePaths = new ArrayList<Resource>();
|
||||||
|
resourcePaths.add(new ClassPathResource("test/foo.css", getClass()));
|
||||||
|
this.handler.setLocations(resourcePaths);
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/foo.css");
|
||||||
|
request.setMethod("GET");
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
handler.handleRequest(request, response);
|
||||||
|
assertEquals("text/css", response.getContentType());
|
||||||
|
assertEquals(17, response.getContentLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestServletContext extends MockServletContext {
|
private static class TestServletContext extends MockServletContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user