JDK 8 + Spring Core 5.2.2.RELEASE
Calling:URL org.springframework.core.io.UrlResource.createRelativeURL(String relativePath)
having this.url = file:./../../../configuration/ and relativePath = foo/bar.xml
results in:
file:../configuration/foo/bar.xml
Corruption happens on line: return new URL(this.url, relativePath);
Seems to be a known bug in JDK, see: https://stackoverflow.com/questions/204784/how-to-construct-a-relative-path-in-java-from-two-absolute-paths-or-urls
Comment From: sbrannen
If I correctly interpreted RFC 2396, the supplied reference URL file:./../../../configuration/ "is considered to be in error" (section 5.2 g), and the following are valid outcomes.
Implementations may handle this error by retaining these components in the resolved path (i.e., treating them as part of the final URI), by removing them from the resolved path (i.e., discarding relative levels above the root), or by avoiding traversal of the reference.
Thus, the implementation could return file:../../../configuration/foo/bar.xml or file:/configuration/foo/bar.xml; whereas, it currently returns file:../configuration/foo/bar.xml.
In any case, I am not quite sure how Spring could pick the "better" result, since they are both rather different.
Note that if you leave off the leading ./ in your reference URL, the relative outcome would be file:../configuration/foo/bar.xml.
So that actually seems rather consistent to me.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.