Avoid duplicate resources in PathMatchingResourcePatternResolver on Windows

This commit updates PathMatchingResourcePatternResolver to avoid
returning duplicate resources on MS Windows when searching using the
`classpath*:` prefix and a wildcard pattern that matches resources
which are directly present in a JAR as well as present via classpath
manifest entries.

Closes gh-31598
This commit is contained in:
Jason 2023-11-13 20:17:37 +08:00 committed by Sam Brannen
parent 99327b7db1
commit d5874ab99e
1 changed files with 2 additions and 1 deletions

View File

@ -491,7 +491,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
int prefixIndex = filePath.indexOf(':');
if (prefixIndex == 1) {
// Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection
filePath = StringUtils.capitalize(filePath);
// to resolve find duplicate jar resource on windows
filePath = "/" + StringUtils.capitalize(filePath);
}
// Since '#' can appear in directories/filenames, java.net.URL should not treat it as a fragment
filePath = StringUtils.replace(filePath, "#", "%23");