Modified impl of bugfix #2350

URL encode/decode host parameter in SFTP URI

This version is slightly different than the original PR, given
this branch's changes to SftpStorage.buildFullPath().
This commit is contained in:
Rick Brown
2023-06-16 19:40:01 -04:00
parent 5e265d1816
commit da5533ef3b

View File

@@ -503,6 +503,7 @@ public class SftpStorage extends JavaFileStorageBase {
public ConnectionInfo splitStringToConnectionInfo(String filename)
throws UnsupportedEncodingException {
ConnectionInfo ci = new ConnectionInfo();
ci.host = extractUserPwdHostPort(filename);
@@ -518,12 +519,17 @@ public class SftpStorage extends JavaFileStorageBase {
ci.host = ci.host.substring(ci.host.indexOf('@') + 1);
ci.port = DEFAULT_SFTP_PORT;
int portSeparatorIndex = ci.host.indexOf(":");
int portSeparatorIndex = ci.host.lastIndexOf(':');
if (portSeparatorIndex >= 0)
{
ci.port = Integer.parseInt(ci.host.substring(portSeparatorIndex + 1));
ci.host = ci.host.substring(0, portSeparatorIndex);
}
// Encode/decode required to support IPv6 (colons break host:port parse logic)
// See Bug #2350
ci.host = decode(ci.host);
ci.localPath = extractSessionPath(filename);
Map<String, String> options = extractOptionsMap(filename);
@@ -625,7 +631,10 @@ public class SftpStorage extends JavaFileStorageBase {
if (password != null) {
uri.append(":").append(encode(password));
}
uri.append("@").append(host);
uri.append("@");
// Encode/decode required to support IPv6 (colons break host:port parse logic)
// See Bug #2350
uri.append(encode(host));
if (port != DEFAULT_SFTP_PORT) {
uri.append(":").append(port);