From 112335c3fc8da655f61e96ad91746e779d93c88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Thu, 31 Oct 2024 16:21:35 -0700 Subject: [PATCH] fix: respect port in GitHub URLs Previously, when reconstructing the domain, we dropped the port completely. --- axoupdater/src/release/github.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/axoupdater/src/release/github.rs b/axoupdater/src/release/github.rs index e1adf4a..180ac4f 100644 --- a/axoupdater/src/release/github.rs +++ b/axoupdater/src/release/github.rs @@ -35,7 +35,8 @@ fn github_api(app_name: &str) -> AxoupdateResult { url: value, }); }; - Ok(format!("{}://api.{}", parsed.scheme(), domain)) + let port = parsed.port().map(|p| format!(":{p}")).unwrap_or_default(); + Ok(format!("{}://api.{}{}", parsed.scheme(), domain, port)) } else { Ok("https://api.github.com".to_string()) } @@ -376,6 +377,16 @@ mod test { assert!(result.is_err()); } + #[test] + #[serial] // modifying the global state environment variables + fn test_github_api_overwrite_port() { + env::set_var("DIST_INSTALLER_GITHUB_BASE_URL", "https://magic.com:8000"); + let result = github_api("dist").unwrap(); + env::remove_var("DIST_INSTALLER_GITHUB_BASE_URL"); + + assert_eq!(result, "https://api.magic.com:8000"); + } + #[test] #[serial] // modifying the global state environment variables fn test_github_api_overwrite_bad_value() {