Align UriComponents.toUri() with toUriString()
Update HierarchicalUriComponents.toUri() to only prepend a missing '/' when the scheme, user info, host or port are specified. This makes the toUri() method behave in the same way as .toUriString() and allows relative URIs to be created. Issue: SPR-10231
This commit is contained in:
@@ -407,7 +407,10 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
else {
|
||||
String path = getPath();
|
||||
if (StringUtils.hasLength(path) && path.charAt(0) != PATH_DELIMITER) {
|
||||
path = PATH_DELIMITER + path;
|
||||
// Only prefix the path delimiter if something exists before it
|
||||
if(getScheme() != null || getUserInfo() != null || getHost() != null || getPort() != -1) {
|
||||
path = PATH_DELIMITER + path;
|
||||
}
|
||||
}
|
||||
return new URI(getScheme(), getUserInfo(), getHost(), getPort(), path, getQuery(),
|
||||
getFragment());
|
||||
|
||||
Reference in New Issue
Block a user