mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Merge branch '7.0.x'
This commit is contained in:
+6
-1
@@ -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
|
||||
|
||||
+3
@@ -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 -> {
|
||||
|
||||
+8
@@ -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());
|
||||
|
||||
+6
-1
@@ -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
|
||||
|
||||
+3
@@ -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;
|
||||
|
||||
+8
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user