Browse Source

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.

See gh-31598
Closes gh-31603

(cherry picked from commit d5874ab99e)
pull/32029/head
Jason 2 years ago committed by Sam Brannen
parent
commit
af593588d3
  1. 3
      spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

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

@ -430,7 +430,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol @@ -430,7 +430,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);
}
// # can appear in directories/filenames, java.net.URL should not treat it as a fragment
filePath = StringUtils.replace(filePath, "#", "%23");

Loading…
Cancel
Save