summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-09-05 20:31:02 +0200
committerCyborus <cyborus@cyborus.xyz>2024-09-05 20:31:02 +0200
commit5abfa90cafd51470e003402b9aa21ad94617f657 (patch)
tree2c196ec850e42a17c1cca478bb958f0090fef300
parentMerge pull request 'host aliases' (#125) from alias-host into main (diff)
downloadforgejo-cli-5abfa90cafd51470e003402b9aa21ad94617f657.tar.xz
forgejo-cli-5abfa90cafd51470e003402b9aa21ad94617f657.zip
fix: make sure urls are http(s) and remove username
-rw-r--r--src/repo.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/repo.rs b/src/repo.rs
index c55c51b..7c76b61 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -166,7 +166,15 @@ impl RepoInfo {
(host_url, None)
};
- let url = url.or_else(fallback_host);
+ let url = url.or_else(fallback_host).map(|url| {
+ let mut url = match url.scheme() {
+ "http" | "https" => url,
+ _ => url::Url::parse(&format!("https{}", &url[url::Position::AfterScheme..]))
+ .expect("should always be valid"),
+ };
+ url.set_username("").expect("shouldn't fail");
+ url
+ });
let info = match (url, name) {
(Some(url), name) => RepoInfo { url, name },