Skip to content

Commit 2bfff7f

Browse files
committed
Retain original URL instance in case of custom URLStreamHandler
Closes gh-33199
1 parent 1880e10 commit 2bfff7f

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
@@ -428,12 +428,18 @@ protected Resource convertClassLoaderURL(URL url) {
428428
if (!cleanedPath.equals(urlString)) {
429429
// Prefer cleaned URL, aligned with UrlResource#createRelative(String)
430430
try {
431-
return new UrlResource(ResourceUtils.toURI(cleanedPath));
431+
// Cannot test for URLStreamHandler directly: URL equality for same String
432+
// in order to find out whether original URL uses default URLStreamHandler.
433+
if (ResourceUtils.toURL(urlString).equals(url)) {
434+
// Plain URL with default URLStreamHandler -> replace with cleaned path.
435+
return new UrlResource(ResourceUtils.toURI(cleanedPath));
436+
}
432437
}
433438
catch (URISyntaxException | MalformedURLException ex) {
434439
// Fallback to regular URL construction below...
435440
}
436441
}
442+
// Retain original URL instance, potentially including custom URLStreamHandler.
437443
return new UrlResource(url);
438444
}
439445
}

0 commit comments

Comments
 (0)