Skip to content

Commit 70bca99

Browse files
committed
VersionResourceResolver should delegate to the chain
Prior to this commit, the `VersionResourceResolver` implementation of `resolveUrlPathInternal` would delegate to the resolver chain but would never use the give result if the current request didn't match a configured version strategy pattern. This is a problem if the resolver supposed to resolve the resource path is configured after a `VersionResourceResolver` in the resolver chain; this means that other resolver never gets to participate in the result of the chain. Issue: SPR-15372 (cherry picked from commit fdd5031)
1 parent 83617f3 commit 70bca99

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -205,7 +205,7 @@ protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends R
205205
if (StringUtils.hasText(baseUrl)) {
206206
VersionStrategy versionStrategy = getStrategyForPath(resourceUrlPath);
207207
if (versionStrategy == null) {
208-
return null;
208+
return baseUrl;
209209
}
210210
if (logger.isTraceEnabled()) {
211211
logger.trace("Getting the original resource to determine version for path \"" + resourceUrlPath + "\"");

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -182,5 +182,12 @@ public void shouldConfigureFixedPrefixAutomatically() throws Exception {
182182
assertThat(this.resolver.getStrategyForPath("fixedversion/css/something.css"), Matchers.instanceOf(FixedVersionStrategy.class));
183183
}
184184

185+
@Test // SPR-15372
186+
public void resolveUrlPathNoVersionStrategy() throws Exception {
187+
given(this.chain.resolveUrlPath("/foo.css", this.locations)).willReturn("/foo.css");
188+
String resolved = this.resolver.resolveUrlPathInternal("/foo.css", this.locations, this.chain);
189+
assertThat(resolved, is("/foo.css"));
190+
}
191+
185192

186193
}

0 commit comments

Comments
 (0)