Skip to content

Commit d1f9e35

Browse files
committed
Merge branch '6.1.x'
2 parents 022b919 + 2bfff7f commit d1f9e35

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,18 @@ protected Resource convertClassLoaderURL(URL url) {
445445
if (!cleanedPath.equals(urlString)) {
446446
// Prefer cleaned URL, aligned with UrlResource#createRelative(String)
447447
try {
448-
return new UrlResource(ResourceUtils.toURI(cleanedPath));
448+
// Cannot test for URLStreamHandler directly: URL equality for same String
449+
// in order to find out whether original URL uses default URLStreamHandler.
450+
if (ResourceUtils.toURL(urlString).equals(url)) {
451+
// Plain URL with default URLStreamHandler -> replace with cleaned path.
452+
return new UrlResource(ResourceUtils.toURI(cleanedPath));
453+
}
449454
}
450455
catch (URISyntaxException | MalformedURLException ex) {
451456
// Fallback to regular URL construction below...
452457
}
453458
}
459+
// Retain original URL instance, potentially including custom URLStreamHandler.
454460
return new UrlResource(url);
455461
}
456462
}

0 commit comments

Comments
 (0)