Skip to content

Commit 3ffb782

Browse files
committed
fix: ssh schema parsing
1 parent b3e5069 commit 3ffb782

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/types/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ impl GitUrl {
229229
// We use the GitUrlParseHint to validate or adjust formatting path, if necessary
230230
let hint = if let Some(scheme) = scheme.as_ref() {
231231
if scheme.contains("ssh") {
232-
GitUrlParseHint::Sshlike
232+
// ssh:// URLs without user should behave like HTTP
233+
// ssh:// URLs with user should behave like SSH
234+
if user.is_none() {
235+
GitUrlParseHint::Httplike
236+
} else {
237+
GitUrlParseHint::Sshlike
238+
}
233239
} else {
234240
match scheme.to_lowercase().as_str() {
235241
"file" => GitUrlParseHint::Filelike,

tests/parse.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ fn ssh_no_scheme_no_user() {
3535
assert_eq!(parsed.print_scheme(), false);
3636
}
3737

38+
#[test]
39+
fn git_plus_ssh_schema() {
40+
let _ = env_logger::try_init();
41+
let test_url = "git+ssh://host.tld/user/project-name.git";
42+
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
43+
debug!("{:#?}", parsed);
44+
45+
assert_eq!(parsed.to_string(), test_url);
46+
assert_eq!(parsed.scheme(), Some("git+ssh"));
47+
assert_eq!(parsed.user(), None);
48+
assert_eq!(parsed.password(), None);
49+
assert_eq!(parsed.host(), Some("host.tld"));
50+
assert_eq!(parsed.port(), None);
51+
assert_eq!(parsed.path(), "/user/project-name.git");
52+
assert_eq!(parsed.print_scheme(), true);
53+
}
54+
55+
#[test]
56+
fn ssh_schema() {
57+
let _ = env_logger::try_init();
58+
let test_url = "ssh://host.tld/user/project-name.git";
59+
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
60+
debug!("{:#?}", parsed);
61+
62+
assert_eq!(parsed.to_string(), test_url);
63+
assert_eq!(parsed.scheme(), Some("ssh"));
64+
assert_eq!(parsed.user(), None);
65+
assert_eq!(parsed.password(), None);
66+
assert_eq!(parsed.host(), Some("host.tld"));
67+
assert_eq!(parsed.port(), None);
68+
assert_eq!(parsed.path(), "/user/project-name.git");
69+
assert_eq!(parsed.print_scheme(), true);
70+
}
71+
3872
// Specific service support
3973
#[test]
4074
fn https_user_bitbucket() {

0 commit comments

Comments
 (0)