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
master
Brian Clozel 10 years ago
parent 9175fa2148
commit 6b07c53c61
  1. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java
  2. 7
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java

@ -179,7 +179,8 @@ public class PathResourceResolver extends AbstractResourceResolver {
resourcePath = resource.getURL().getPath(); resourcePath = resource.getURL().getPath();
locationPath = StringUtils.cleanPath(location.getURL().getPath()); locationPath = StringUtils.cleanPath(location.getURL().getPath());
} }
locationPath = (locationPath.endsWith("/") || locationPath.isEmpty() ? locationPath : locationPath + "/"); locationPath = (StringUtils.getFilenameExtension(locationPath) != null
|| locationPath.endsWith("/") || locationPath.isEmpty() ? locationPath : locationPath + "/");
if (!resourcePath.startsWith(locationPath)) { if (!resourcePath.startsWith(locationPath)) {
return false; return false;
} }

@ -117,4 +117,11 @@ public class PathResourceResolverTests {
assertNotNull(this.resolver.resolveResource(null, "main.css", Arrays.asList(location), null)); assertNotNull(this.resolver.resolveResource(null, "main.css", Arrays.asList(location), null));
} }
// SPR-12747
@Test
public void checkFileLocation() throws Exception {
Resource resource = new ClassPathResource("test/main.css", PathResourceResolver.class);
assertTrue(this.resolver.checkResource(resource, resource));
}
} }

Loading…
Cancel
Save