Browse Source

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.
pull/530/head
Brian Clozel 11 years ago
parent
commit
c4843577ba
  1. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java
  2. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java

2
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java

@ -50,7 +50,7 @@ public class PrefixResourceResolver extends AbstractResourceResolver { @@ -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

4
spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java

@ -54,14 +54,14 @@ public class PrefixResourceResolverTests { @@ -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));
}

Loading…
Cancel
Save