Merge branch '7.0.x'

This commit is contained in:
Brian Clozel
2026-04-23 16:24:27 +02:00
6 changed files with 34 additions and 2 deletions
@@ -54,7 +54,12 @@ public abstract class AbstractFileNameVersionStrategy implements VersionStrategy
@Override
public String removeVersion(String requestPath, String version) {
return StringUtils.delete(requestPath, "-" + version);
String versionString = "-" + version;
int index = requestPath.lastIndexOf(versionString);
if (index != -1) {
return requestPath.substring(0, index) + requestPath.substring(index + versionString.length());
}
return requestPath;
}
@Override
@@ -180,6 +180,9 @@ public class VersionResourceResolver extends AbstractResourceResolver {
}
String simplePath = versionStrategy.removeVersion(requestPath, candidate);
if (ResourceHandlerUtils.shouldIgnoreInputPath(simplePath)) {
return Mono.empty();
}
return chain.resolveResource(exchange, simplePath, locations)
.filterWhen(resource -> versionStrategy.getResourceVersion(resource)
.map(actual -> {
@@ -62,6 +62,14 @@ class ContentBasedVersionStrategyTests {
assertThat(this.strategy.removeVersion(String.format(path, "-", hash), hash)).isEqualTo(String.format(path, "", ""));
}
@Test
void removeVersionOnlyOnce() {
String hash = "sha";
String path = "font-awesome/css%s%s/font-awesome.min%s%s.css";
assertThat(this.strategy.removeVersion(String.format(path, "-", hash, "-", hash), hash)).isEqualTo(String.format(path, "-", hash, "", ""));
}
@Test
void getResourceVersion() throws Exception {
Resource expected = new ClassPathResource("test/bar.css", getClass());
@@ -134,7 +134,12 @@ public abstract class AbstractVersionStrategy implements VersionStrategy {
@Override
public String removeVersion(String requestPath, String version) {
return StringUtils.delete(requestPath, "-" + version);
String versionString = "-" + version;
int index = requestPath.lastIndexOf(versionString);
if (index != -1) {
return requestPath.substring(0, index) + requestPath.substring(index + versionString.length());
}
return requestPath;
}
@Override
@@ -177,6 +177,9 @@ public class VersionResourceResolver extends AbstractResourceResolver {
}
String simplePath = versionStrategy.removeVersion(requestPath, candidateVersion);
if (ResourceHandlerUtils.shouldIgnoreInputPath(simplePath)) {
return null;
}
Resource baseResource = chain.resolveResource(request, simplePath, locations);
if (baseResource == null) {
return null;
@@ -63,6 +63,14 @@ class ContentBasedVersionStrategyTests {
assertThat(this.versionStrategy.removeVersion(String.format(file, "-", hash), hash)).isEqualTo(String.format(file, "", ""));
}
@Test
void removeVersionOnlyOnce() {
String hash = "sha";
String file = "font-awesome/css%s%s/font-awesome.min%s%s.css";
assertThat(this.versionStrategy.removeVersion(String.format(file, "-", hash, "-", hash), hash)).isEqualTo(String.format(file, "-", hash, "", ""));
}
@Test
void getResourceVersion() throws IOException {
Resource expected = new ClassPathResource("test/bar.css", getClass());