File tree 1 file changed +11
-5
lines changed
spring-core/src/main/java/org/springframework/core/io
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -101,9 +101,10 @@ public UrlResource(String path) throws MalformedURLException {
101
101
// Equivalent without java.net.URL constructor - for building on JDK 20+
102
102
/*
103
103
try {
104
- this.uri = ResourceUtils.toURI(StringUtils.cleanPath(path));
104
+ String cleanedPath = StringUtils.cleanPath(path);
105
+ this.uri = ResourceUtils.toURI(cleanedPath);
105
106
this.url = this.uri.toURL();
106
- this.cleanedUrl = StringUtils.cleanPath(path) ;
107
+ this.cleanedUrl = cleanedPath ;
107
108
}
108
109
catch (URISyntaxException | IllegalArgumentException ex) {
109
110
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
@@ -319,9 +320,14 @@ protected URL createRelativeURL(String relativePath) throws MalformedURLExceptio
319
320
@ Override
320
321
@ Nullable
321
322
public String getFilename () {
322
- String originalPath = (this .uri != null ? this .uri .getPath () : this .url .getPath ());
323
- String filename = StringUtils .getFilename (StringUtils .cleanPath (originalPath ));
324
- return (filename != null ? URLDecoder .decode (filename , StandardCharsets .UTF_8 ) : null );
323
+ if (this .uri != null ) {
324
+ // URI path is decoded and has standard separators
325
+ return StringUtils .getFilename (this .uri .getPath ());
326
+ }
327
+ else {
328
+ String filename = StringUtils .getFilename (StringUtils .cleanPath (this .url .getPath ()));
329
+ return (filename != null ? URLDecoder .decode (filename , StandardCharsets .UTF_8 ) : null );
330
+ }
325
331
}
326
332
327
333
/**
You can’t perform that action at this time.
0 commit comments