Parse SSH URL usernames consistently
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:20:09 -04:00
parent f8c93c44f1
commit 4f1d192f7a
2 changed files with 19 additions and 1 deletions
+10
View File
@@ -5271,6 +5271,7 @@ fn native_proxy_udp_warning(
fn ssh_username(server: &str) -> Option<String> {
let (user, _) = server.rsplit_once('@')?;
let user = user.strip_prefix("ssh://").unwrap_or(user);
if user.is_empty() {
None
} else {
@@ -11433,7 +11434,16 @@ mod tests {
#[test]
fn parses_user_from_ssh_destination() {
assert_eq!(ssh_username("alice@example.com"), Some("alice".to_string()));
assert_eq!(
ssh_username("ssh://alice@example.com:2222/srv/app"),
Some("alice".to_string())
);
assert_eq!(
ssh_username("ssh://alice@[2001:db8::1]:2222/srv/app"),
Some("alice".to_string())
);
assert_eq!(ssh_username("example.com"), None);
assert_eq!(ssh_username("ssh://example.com:2222/srv/app"), None);
}
#[test]
+9 -1
View File
@@ -786,7 +786,7 @@ fn selected_sdk_udp_host(
fn user_from_destination(destination: &str) -> Option<String> {
destination
.rsplit_once('@')
.map(|(user, _)| user.to_string())
.map(|(user, _)| user.strip_prefix("ssh://").unwrap_or(user).to_string())
.filter(|user| !user.is_empty())
}
@@ -819,6 +819,14 @@ mod tests {
user_from_destination("palav@example.com").as_deref(),
Some("palav")
);
assert_eq!(
user_from_destination("ssh://palav@example.com:2222/srv/app").as_deref(),
Some("palav")
);
assert_eq!(
user_from_destination("ssh://palav@[2001:db8::2]:2222/srv/app").as_deref(),
Some("palav")
);
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");