Process URL path for filename extraction if URI does not expose path

Closes gh-31718
This commit is contained in:
Juergen Hoeller
2023-11-29 17:08:59 +01:00
parent df00aafdff
commit f3b1f37000
2 changed files with 25 additions and 6 deletions

View File

@@ -332,13 +332,15 @@ public class UrlResource extends AbstractFileResolvingResource {
@Nullable
public String getFilename() {
if (this.uri != null) {
// URI path is decoded and has standard separators
return StringUtils.getFilename(this.uri.getPath());
}
else {
String filename = StringUtils.getFilename(StringUtils.cleanPath(this.url.getPath()));
return (filename != null ? URLDecoder.decode(filename, StandardCharsets.UTF_8) : null);
String path = this.uri.getPath();
if (path != null) {
// Prefer URI path: decoded and has standard separators
return StringUtils.getFilename(this.uri.getPath());
}
}
// Otherwise, process URL path
String filename = StringUtils.getFilename(StringUtils.cleanPath(this.url.getPath()));
return (filename != null ? URLDecoder.decode(filename, StandardCharsets.UTF_8) : null);
}
/**