Skip to content

Commit

Permalink
Straight filename extraction for URI path (decoded and standard separ…
Browse files Browse the repository at this point in the history
…ators)

See gh-29486
  • Loading branch information
jhoeller committed Nov 15, 2022
1 parent abf3400 commit f8b4be3
Showing 1 changed file with 11 additions and 5 deletions.
Expand Up @@ -101,9 +101,10 @@ public UrlResource(String path) throws MalformedURLException {
// Equivalent without java.net.URL constructor - for building on JDK 20+
/*
try {
this.uri = ResourceUtils.toURI(StringUtils.cleanPath(path));
String cleanedPath = StringUtils.cleanPath(path);
this.uri = ResourceUtils.toURI(cleanedPath);
this.url = this.uri.toURL();
this.cleanedUrl = StringUtils.cleanPath(path);
this.cleanedUrl = cleanedPath;
}
catch (URISyntaxException | IllegalArgumentException ex) {
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
Expand Down Expand Up @@ -319,9 +320,14 @@ protected URL createRelativeURL(String relativePath) throws MalformedURLExceptio
@Override
@Nullable
public String getFilename() {
String originalPath = (this.uri != null ? this.uri.getPath() : this.url.getPath());
String filename = StringUtils.getFilename(StringUtils.cleanPath(originalPath));
return (filename != null ? URLDecoder.decode(filename, StandardCharsets.UTF_8) : null);
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);
}
}

/**
Expand Down

0 comments on commit f8b4be3

Please sign in to comment.