diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java index 475f40b390..4750d9c5d6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java @@ -179,7 +179,8 @@ public class PathResourceResolver extends AbstractResourceResolver { resourcePath = resource.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)) { return false; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java index d4839e53ed..eb9162ac9e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java @@ -117,4 +117,11 @@ public class PathResourceResolverTests { 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)); + } + }