Current behavior 😯
In SCP-like URL, the path git@github.com:rust-lang/cargo.git is home-relative. The path ought to be ~git/rust-lang/cargo.git. However, gix-url@0.35.2 converts git@github.com:rust-lang/cargo.git to ssh://git@github.com/rust-lang/cargo.git, which is lossy (not wrong). That SSH URL is absolute /rust-lang/cargo.git.
Expected behavior 🤔
I don't really know.
git@github.com:rust-lang/cargo.git -> ssh://git@github.com/~/rust-lang/cargo.git seems to be a more correct behavior. However, as I found in rust-lang/cargo#16740 (comment), GitHub doesn't recognize ssh://git@github.com/~/rust-lang/cargo.git (perhaps for security reason to prevent file system traversal?)
Git behavior
Not related to Git. Git doesn't do conversion.
Steps to reproduce 🕹
Run this cargo script cargo +nightly -Zscript script.rs
---cargo
package.edition = "2024"
dependencies.gix-url = "=0.35.2"
---
fn main() {
for url in [
"git@github.com:rust-lang/cargo.git",
"git@github.com:/rust-lang/cargo.git",
"git@github.com:~/rust-lang/cargo.git",
"git@github.com:~git/rust-lang/cargo.git",
"git@github.com:/~/rust-lang/cargo.git",
"git@github.com:/~git/rust-lang/cargo.git",
] {
print(url);
eprintln!();
}
}
fn print(url: &str) {
let scp = gix_url::parse(url.into()).unwrap();
let canonical = scp.clone().serialize_alternate_form(false).to_bstring();
eprintln!("SCP-like: {url}");
eprintln!("path: {}", std::str::from_utf8(&scp.path).unwrap());
eprintln!("SSH URL: {}", std::str::from_utf8(&canonical).unwrap());
}
Output:
SCP-like: git@github.com:rust-lang/cargo.git
path: rust-lang/cargo.git
SSH URL: ssh://git@github.com/rust-lang/cargo.git
SCP-like: git@github.com:/rust-lang/cargo.git
path: /rust-lang/cargo.git
SSH URL: ssh://git@github.com/rust-lang/cargo.git
SCP-like: git@github.com:~/rust-lang/cargo.git
path: ~/rust-lang/cargo.git
SSH URL: ssh://git@github.com/~/rust-lang/cargo.git
SCP-like: git@github.com:~git/rust-lang/cargo.git
path: ~git/rust-lang/cargo.git
SSH URL: ssh://git@github.com/~git/rust-lang/cargo.git
SCP-like: git@github.com:/~/rust-lang/cargo.git
path: ~/rust-lang/cargo.git
SSH URL: ssh://git@github.com/~/rust-lang/cargo.git
SCP-like: git@github.com:/~git/rust-lang/cargo.git
path: ~git/rust-lang/cargo.git
SSH URL: ssh://git@github.com/~git/rust-lang/cargo.git
Current behavior 😯
In SCP-like URL, the path
git@github.com:rust-lang/cargo.gitis home-relative. The path ought to be~git/rust-lang/cargo.git. However,gix-url@0.35.2convertsgit@github.com:rust-lang/cargo.gittossh://git@github.com/rust-lang/cargo.git, which is lossy (not wrong). That SSH URL is absolute/rust-lang/cargo.git.Expected behavior 🤔
I don't really know.
git@github.com:rust-lang/cargo.git->ssh://git@github.com/~/rust-lang/cargo.gitseems to be a more correct behavior. However, as I found in rust-lang/cargo#16740 (comment), GitHub doesn't recognizessh://git@github.com/~/rust-lang/cargo.git(perhaps for security reason to prevent file system traversal?)Git behavior
Not related to Git. Git doesn't do conversion.
Steps to reproduce 🕹
Run this cargo script
cargo +nightly -Zscript script.rsOutput: