Enfoce single version removal in content versioning

Prior to this commit, content based version strategies would remove all
instances of the version string in the request path when trying to
resolve the original resource with the chain.
This can cause issues in rare cases where there is a collision between
the content version and some other version string in the request path.

Because this strategy is based on the contents of the file itself, we
should only remove the last instance of the version string and then
attempt to resolve the original file.

Fixes gh-36698
This commit is contained in:
Brian Clozel
2026-04-23 15:04:02 +02:00
parent fb0c78ae27
commit 8d51f47357
6 changed files with 34 additions and 2 deletions
@@ -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());