Enforce cleaned URL for root resource from ClassLoader

Closes gh-32828
This commit is contained in:
Juergen Hoeller 2024-05-15 14:15:47 +02:00
parent 70886e32c0
commit 2270df515b
1 changed files with 11 additions and 0 deletions

View File

@ -423,6 +423,17 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
}
}
else {
String urlString = url.toString();
String cleanedPath = StringUtils.cleanPath(urlString);
if (!cleanedPath.equals(urlString)) {
// Prefer cleaned URL, aligned with UrlResource#createRelative(String)
try {
return new UrlResource(ResourceUtils.toURI(cleanedPath));
}
catch (URISyntaxException | MalformedURLException ex) {
// Fallback to regular URL construction below...
}
}
return new UrlResource(url);
}
}