Skip to content

Commit d5874ab

Browse files
huyachigegesbrannen
authored andcommitted
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
1 parent 99327b7 commit d5874ab

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ protected void addClassPathManifestEntries(Set<Resource> result) {
491491
int prefixIndex = filePath.indexOf(':');
492492
if (prefixIndex == 1) {
493493
// Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection
494-
filePath = StringUtils.capitalize(filePath);
494+
// to resolve find duplicate jar resource on windows
495+
filePath = "/" + StringUtils.capitalize(filePath);
495496
}
496497
// Since '#' can appear in directories/filenames, java.net.URL should not treat it as a fragment
497498
filePath = StringUtils.replace(filePath, "#", "%23");

0 commit comments

Comments
 (0)