From c4843577bab0a9ebf5277853dd70a2e01dd1facd Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 24 Apr 2014 14:43:26 +0200 Subject: [PATCH] Fix PrefixResourceResolver implementation The configured prefix should not begin with a "/", since PublicResourceUrlProvider is already taking path mapping into account when resolving resources and URLs. --- .../web/servlet/resource/PrefixResourceResolver.java | 2 +- .../web/servlet/resource/PrefixResourceResolverTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java index 208a5b587b..b5cc6f5246 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java @@ -50,7 +50,7 @@ public class PrefixResourceResolver extends AbstractResourceResolver { public PrefixResourceResolver(String prefix) { Assert.hasText(prefix, "prefix must not be null or empty"); - this.prefix = prefix.startsWith("/") ? prefix : "/" + prefix; + this.prefix = prefix.startsWith("/") ? prefix.substring(1) : prefix; } @Override diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java index d97ef7982d..2f95a135e3 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java @@ -54,14 +54,14 @@ public class PrefixResourceResolverTests { public void resolveResource() { String resourceId = "foo.css"; Resource expected = new ClassPathResource("test/foo.css", getClass()); - Resource actual = this.chain.resolveResource(null, "/" + this.shaPrefix + "/" + resourceId, this.locations); + Resource actual = this.chain.resolveResource(null, this.shaPrefix + "/" + resourceId, this.locations); assertEquals(expected, actual); } @Test public void resolvePublicUrlPath() { String resourceId = "/foo.css"; - String url = "/" + this.shaPrefix + resourceId; + String url = this.shaPrefix + resourceId; assertEquals(url, chain.resolvePublicUrlPath(resourceId, locations)); }