diff --git a/src/bin/dosh-client.rs b/src/bin/dosh-client.rs index 0971949..87ace7a 100644 --- a/src/bin/dosh-client.rs +++ b/src/bin/dosh-client.rs @@ -5271,6 +5271,7 @@ fn native_proxy_udp_warning( fn ssh_username(server: &str) -> Option { 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] diff --git a/src/client.rs b/src/client.rs index 3348144..a3d5d51 100644 --- a/src/client.rs +++ b/src/client.rs @@ -786,7 +786,7 @@ fn selected_sdk_udp_host( fn user_from_destination(destination: &str) -> Option { 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");