Add explicit FileSystemResource path check for trailing slash

Closes gh-34509
This commit is contained in:
Juergen Hoeller
2025-03-04 18:44:25 +01:00
parent e421104cf3
commit 534f123fe8
4 changed files with 45 additions and 12 deletions

View File

@@ -24,7 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.PathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.core.log.LogFormatUtils;
@@ -57,15 +57,18 @@ public abstract class ResourceHandlerUtils {
Assert.notNull(location, "Resource location must not be null");
try {
String path;
if (location instanceof PathResource) {
if (location instanceof org.springframework.core.io.PathResource) {
return;
}
else if (location instanceof UrlResource) {
path = location.getURL().toExternalForm();
else if (location instanceof FileSystemResource fileSystemResource) {
path = fileSystemResource.getPath();
}
else if (location instanceof ClassPathResource classPathResource) {
path = classPathResource.getPath();
}
else if (location instanceof UrlResource) {
path = location.getURL().toExternalForm();
}
else {
path = location.getURL().getPath();
}