Browse Source

VersionResourceResolver should delegate to the chain

Prior to this commit, the `VersionResourceResolver` implementations 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
pull/1366/head
Brian Clozel 9 years ago
parent
commit
fdd503152d
  1. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java
  2. 10
      spring-webflux/src/test/java/org/springframework/web/reactive/resource/VersionResourceResolverTests.java
  3. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java
  4. 9
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/VersionResourceResolverTests.java

4
spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -212,7 +212,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { @@ -212,7 +212,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
if (StringUtils.hasText(baseUrl)) {
VersionStrategy versionStrategy = getStrategyForPath(resourceUrlPath);
if (versionStrategy == null) {
return Mono.empty();
return Mono.just(baseUrl);
}
if (logger.isTraceEnabled()) {
logger.trace("Getting the original resource to determine version " +

10
spring-webflux/src/test/java/org/springframework/web/reactive/resource/VersionResourceResolverTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -215,5 +215,13 @@ public class VersionResourceResolverTests { @@ -215,5 +215,13 @@ public class VersionResourceResolverTests {
Matchers.instanceOf(FixedVersionStrategy.class));
}
@Test // SPR-15372
public void resolveUrlPathNoVersionStrategy() throws Exception {
given(this.chain.resolveUrlPath("/foo.css", this.locations)).willReturn(Mono.just("/foo.css"));
String resolved = this.resolver.resolveUrlPathInternal("/foo.css", this.locations, this.chain)
.block(Duration.ofMillis(1000));
assertThat(resolved, is("/foo.css"));
}
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -206,7 +206,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { @@ -206,7 +206,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
if (StringUtils.hasText(baseUrl)) {
VersionStrategy versionStrategy = getStrategyForPath(resourceUrlPath);
if (versionStrategy == null) {
return null;
return baseUrl;
}
if (logger.isTraceEnabled()) {
logger.trace("Getting the original resource to determine version for path \"" + resourceUrlPath + "\"");

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -182,5 +182,12 @@ public class VersionResourceResolverTests { @@ -182,5 +182,12 @@ public class VersionResourceResolverTests {
assertThat(this.resolver.getStrategyForPath("fixedversion/css/something.css"), Matchers.instanceOf(FixedVersionStrategy.class));
}
@Test // SPR-15372
public void resolveUrlPathNoVersionStrategy() throws Exception {
given(this.chain.resolveUrlPath("/foo.css", this.locations)).willReturn("/foo.css");
String resolved = this.resolver.resolveUrlPathInternal("/foo.css", this.locations, this.chain);
assertThat(resolved, is("/foo.css"));
}
}

Loading…
Cancel
Save