Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git: Detect SCP remotes with non-standard SSH usernames (#59457)
Ibrahim Khan790b73e2fb79
diff --git a/crates/git/src/remote.rs b/crates/git/src/remote.rsindex 8fb44839848..d64958503eb 100644--- a/crates/git/src/remote.rs+++ b/crates/git/src/remote.rs@@ -9,8 +9,12 @@ use url::Url;#[derive(Debug, PartialEq, Eq, Clone, Deref)]pub struct RemoteUrl(Url);+// Detect the `user@` prefix of an SCP-like remote (e.g. `git@host:path`). The+// username may contain anything but the `@`/`:`/`/` that delimit the user,+// host, and path, so match by exclusion rather than an allowlist that misses+// names like `first.last`.static USERNAME_REGEX: LazyLock<Regex> =- LazyLock::new(|| Regex::new(r"^[0-9a-zA-Z\-_]+@").expect("Failed to create USERNAME_REGEX"));+ LazyLock::new(|| Regex::new(r"^[^/@:]+@").expect("Failed to create USERNAME_REGEX"));impl FromStr for RemoteUrl {type Err = url::ParseError;@@ -41,6 +45,12 @@ mod tests {"github.com","/octocat/zed.git",),+ (+ "https://[email protected]/octocat/zed.git",+ "https",+ "github.com",+ "/octocat/zed.git",+ ),("[email protected]:octocat/zed.git","ssh",@@ -53,6 +63,12 @@ mod tests {"github.com","/octocat/zed.git",),+ (+ "[email protected]:group/repo.git",+ "ssh",+ "gitlab.example.com",+ "/group/repo.git",+ ),("ssh://[email protected]/octocat/zed.git","ssh",