Skip to content

Commit

Permalink
Retain original URL instance in case of custom URLStreamHandler
Browse files Browse the repository at this point in the history
Closes gh-33199
  • Loading branch information
jhoeller committed Jul 11, 2024
1 parent 1880e10 commit 2bfff7f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,18 @@ protected Resource convertClassLoaderURL(URL url) {
if (!cleanedPath.equals(urlString)) {
// Prefer cleaned URL, aligned with UrlResource#createRelative(String)
try {
return new UrlResource(ResourceUtils.toURI(cleanedPath));
// Cannot test for URLStreamHandler directly: URL equality for same String
// in order to find out whether original URL uses default URLStreamHandler.
if (ResourceUtils.toURL(urlString).equals(url)) {
// Plain URL with default URLStreamHandler -> replace with cleaned path.
return new UrlResource(ResourceUtils.toURI(cleanedPath));
}
}
catch (URISyntaxException | MalformedURLException ex) {
// Fallback to regular URL construction below...
}
}
// Retain original URL instance, potentially including custom URLStreamHandler.
return new UrlResource(url);
}
}
Expand Down

0 comments on commit 2bfff7f

Please sign in to comment.