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 45f3b9e286..0b3f777e12 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 @@ -82,7 +82,7 @@ public class PathResourceResolver extends AbstractResourceResolver { protected String resolveUrlPathInternal(String resourcePath, List locations, ResourceResolverChain chain) { - return (getResource(resourcePath, locations) != null ? resourcePath : null); + return (StringUtils.hasText(resourcePath) && getResource(resourcePath, locations) != null ? resourcePath : null); } private Resource getResource(String resourcePath, List locations) { 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 eb9162ac9e..7807011631 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 @@ -124,4 +124,15 @@ public class PathResourceResolverTests { assertTrue(this.resolver.checkResource(resource, resource)); } + // SPR-13241 + @Test + public void resolvePathRootResource() throws Exception { + Resource webjarsLocation = new ClassPathResource("/META-INF/resources/webjars/", PathResourceResolver.class); + Resource actual = this.resolver.resolveResource(null, "", Arrays.asList(webjarsLocation), null); + String path = this.resolver.resolveUrlPathInternal("", Arrays.asList(webjarsLocation), null); + + assertNotNull(actual); + assertTrue(actual.exists() && actual.isReadable()); + assertNull(path); + } }