From a0f995d2aec9c185da9c760846d1f17b382061e3 Mon Sep 17 00:00:00 2001 From: Color Fuzzy Date: Mon, 17 Mar 2025 13:10:21 +0800 Subject: [PATCH] Support SSH usernames which contain @ symbols (#25314) Closes #25246 Release Notes: - SSH: Improved handling of multiple `@` in connection strings: e.g. `ssh jim.lv@es2@10.220.67.57@11.239.1.231` improving support of jump hosts running JumpServer. --------- Co-authored-by: Conrad Irwin --- Cargo.lock | 1 + Cargo.toml | 1 + crates/feedback/Cargo.toml | 2 +- crates/remote/Cargo.toml | 1 + crates/remote/src/ssh_session.rs | 7 +++++-- crates/zed/Cargo.toml | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56f17318aa36207b36dce4b2fe7e3bbd147e52c2..5ea631d7c4f9a75f2209196dac97b50a85fbe43d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11253,6 +11253,7 @@ dependencies = [ "smol", "tempfile", "thiserror 1.0.69", + "urlencoding", "util", ] diff --git a/Cargo.toml b/Cargo.toml index 4f853a62048ac701feb60d6f9e742bafcf3ec065..d0145940c096ce5822bcc4a5e638bf6a69a7b201 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -565,6 +565,7 @@ unindent = "0.2.0" unicode-segmentation = "1.10" unicode-script = "0.5.7" url = "2.2" +urlencoding = "2.1.2" uuid = { version = "1.1.2", features = ["v4", "v5", "v7", "serde"] } wasmparser = "0.221" wasm-encoder = "0.221" diff --git a/crates/feedback/Cargo.toml b/crates/feedback/Cargo.toml index 75264a970ac9a001788e472ac058495955fbbc4d..05577afc0445f643835e3d6228300ce25f9ed5a0 100644 --- a/crates/feedback/Cargo.toml +++ b/crates/feedback/Cargo.toml @@ -36,7 +36,7 @@ serde_json.workspace = true smol.workspace = true sysinfo.workspace = true ui.workspace = true -urlencoding = "2.1.2" +urlencoding.workspace = true util.workspace = true workspace.workspace = true zed_actions.workspace = true diff --git a/crates/remote/Cargo.toml b/crates/remote/Cargo.toml index 4bb33d6db448c64aa269ba5704e8316d7d1d892a..43edb8cdc8a52c177c13774a9dc8983fb385d9ca 100644 --- a/crates/remote/Cargo.toml +++ b/crates/remote/Cargo.toml @@ -39,6 +39,7 @@ shlex.workspace = true smol.workspace = true tempfile.workspace = true thiserror.workspace = true +urlencoding.workspace = true util.workspace = true [dev-dependencies] diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index 0309fb5da944a99a0dd3438f354104019c3670fb..d254526e1882d542bf7dd794be6125ee0a5a5570 100644 --- a/crates/remote/src/ssh_session.rs +++ b/crates/remote/src/ssh_session.rs @@ -203,7 +203,8 @@ impl SshConnectionOptions { anyhow::bail!("unsupported argument: {:?}", arg); } let mut input = &arg as &str; - if let Some((u, rest)) = input.split_once('@') { + // Destination might be: username1@username2@ip2@ip1 + if let Some((u, rest)) = input.rsplit_once('@') { input = rest; username = Some(u.to_string()); } @@ -238,7 +239,9 @@ impl SshConnectionOptions { pub fn ssh_url(&self) -> String { let mut result = String::from("ssh://"); if let Some(username) = &self.username { - result.push_str(username); + // Username might be: username1@username2@ip2 + let username = urlencoding::encode(username); + result.push_str(&username); result.push('@'); } result.push_str(&self.host); diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index af7eec4df7c1ad7b9e75ad8dcba852192879a809..c5e53b817bb820adae2c881e006710d07d6b7094 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -124,7 +124,7 @@ time.workspace = true toolchain_selector.workspace = true ui.workspace = true url.workspace = true -urlencoding = "2.1.2" +urlencoding.workspace = true util.workspace = true uuid.workspace = true vim.workspace = true