Align SDK SSH destination parsing with CLI
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s

This commit is contained in:
DuProcess
2026-07-16 22:18:12 -04:00
parent dba598a7fa
commit f8c93c44f1
+40 -6
View File
@@ -731,13 +731,23 @@ fn first_resolved_addr(addrs: &[SocketAddr], host: &str, port: u16) -> Result<So
}
fn destination_host(destination: &str) -> String {
destination
.rsplit('@')
let without_user = destination
.rsplit_once('@')
.map_or(destination, |(_, host)| host);
let without_path = without_user
.strip_prefix("ssh://")
.unwrap_or(without_user)
.split('/')
.next()
.unwrap_or(destination)
.split(':')
.next()
.unwrap_or(destination)
.unwrap_or(without_user);
if let Some(stripped) = without_path.strip_prefix('[')
&& let Some((host, _)) = stripped.split_once(']')
{
return host.to_string();
}
without_path
.split_once(':')
.map_or(without_path, |(host, _)| host)
.to_string()
}
@@ -811,6 +821,15 @@ mod tests {
);
assert_eq!(destination_host("palav@example.com"), "example.com");
assert_eq!(destination_host("example.com:2222"), "example.com");
assert_eq!(destination_host("palav@[2001:db8::1]:2222"), "2001:db8::1");
assert_eq!(
destination_host("ssh://palav@example.com:2222/srv/app"),
"example.com"
);
assert_eq!(
destination_host("ssh://palav@[2001:db8::2]:2222/srv/app"),
"2001:db8::2"
);
}
#[test]
@@ -880,6 +899,21 @@ mod tests {
);
}
#[test]
fn sdk_udp_host_preserves_bracketed_ipv6_destination_without_ssh_config() {
assert_eq!(
selected_sdk_udp_host(
None,
&HostConfig::default(),
&ClientConfig::default(),
"deploy@[2001:db8::5]:2222",
&SdkSshConfig::default(),
)
.unwrap(),
"2001:db8::5"
);
}
#[test]
fn sdk_udp_host_honors_cli_compatible_special_values() {
let ssh_config = SdkSshConfig {