From d5874ab99ef62b3da8a9269aa526b43328e968a9 Mon Sep 17 00:00:00 2001 From: Jason <44935830+huyachigege@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:17:37 +0800 Subject: [PATCH 1/2] 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 --- .../core/io/support/PathMatchingResourcePatternResolver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 5666fdbd1d..b1ef54db9a 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -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"); From e71117dcdf8c713b0a364d896ea2221183eac64b Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 14 Nov 2023 14:39:20 +0100 Subject: [PATCH 2/2] Polish contribution See gh-31598 --- .../core/io/support/PathMatchingResourcePatternResolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index b1ef54db9a..67159494bd 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -490,8 +490,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol String filePath = new File(path).getAbsolutePath(); int prefixIndex = filePath.indexOf(':'); if (prefixIndex == 1) { - // Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection - // to resolve find duplicate jar resource on windows + // Possibly a drive prefix on Windows (for example, "c:"), so we prepend a slash + // and convert the drive letter to uppercase for consistent duplicate detection. filePath = "/" + StringUtils.capitalize(filePath); } // Since '#' can appear in directories/filenames, java.net.URL should not treat it as a fragment