Skip to content

Parsing SSH url replaces / with : after hostname #80

@ALameLlama

Description

@ALameLlama

I was trying to use the lux-cli and was running into "malformed hostname" from git2-rs and noticed that the parse seemed to change the url in a way I don't think it should

    let parsed = GitUrl::parse("git+ssh://git.server.au/my/repo.git").unwrap();
    let transformed_url = parsed.to_string();

    println!("  Original:     {}", original_url);
    println!("  Transformed:  {}", transformed_url);
    Original:     ssh://git.server.au/my/repo.git
    Transformed:  ssh://git.server.au:my/repo.git

it's changed the / after the hostname to :

then trying to use this with git2 will error

use git2::build::RepoBuilder;
...

      let temp_dir = format!("/tmp/test-{}", std::process::id());
      
      let mut fetch_opts = FetchOptions::new();
      fetch_opts.depth(1);
      fetch_opts.update_fetchhead(false);
      
      let mut builder = RepoBuilder::new();
      builder.fetch_options(fetch_opts);
      
      match builder.clone(&transformed_url, temp_dir.as_ref()) {
          Ok(_) => {
              println!("  ✓ Clone succeeded");
              let _ = std::fs::remove_dir_all(&temp_dir);
          }
          Err(e) => {
              println!("  ✗ Clone failed");
              println!("    Error: {}", e.message());
              println!("    Code: InvalidSpec ({})", e.raw_code());
              println!("    Class: Net ({})", e.raw_class());
              let _ = std::fs::remove_dir_all(&temp_dir);
          }
      }
}

will error with

  ✗ Clone failed
    Error: invalid url: malformed hostname
    Code: InvalidSpec (-12)
    Class: Net (12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions