Skip to content

Commit c484357

Browse files
committed
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.
1 parent bded025 commit c484357

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class PrefixResourceResolver extends AbstractResourceResolver {
5050

5151
public PrefixResourceResolver(String prefix) {
5252
Assert.hasText(prefix, "prefix must not be null or empty");
53-
this.prefix = prefix.startsWith("/") ? prefix : "/" + prefix;
53+
this.prefix = prefix.startsWith("/") ? prefix.substring(1) : prefix;
5454
}
5555

5656
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ public void setUp() {
5454
public void resolveResource() {
5555
String resourceId = "foo.css";
5656
Resource expected = new ClassPathResource("test/foo.css", getClass());
57-
Resource actual = this.chain.resolveResource(null, "/" + this.shaPrefix + "/" + resourceId, this.locations);
57+
Resource actual = this.chain.resolveResource(null, this.shaPrefix + "/" + resourceId, this.locations);
5858
assertEquals(expected, actual);
5959
}
6060

6161
@Test
6262
public void resolvePublicUrlPath() {
6363
String resourceId = "/foo.css";
64-
String url = "/" + this.shaPrefix + resourceId;
64+
String url = this.shaPrefix + resourceId;
6565
assertEquals(url, chain.resolvePublicUrlPath(resourceId, locations));
6666
}
6767

0 commit comments

Comments
 (0)