Retain original URL instance in case of custom URLStreamHandler
Closes gh-33199
This commit is contained in:
parent
1880e109c3
commit
2bfff7fc37
|
@ -428,12 +428,18 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue