diff --git a/src/registry.rs b/src/registry.rs index b465cae4..3e929fdf 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -158,7 +158,19 @@ pub trait Registry { ) -> Result; } +const LEGACY_PUBLIC_REGISTRY_URL: &str = "https://registry.zpkg.net"; +const CANONICAL_PUBLIC_REGISTRY_URL: &str = "https://zpkg.net"; + +fn canonical_registry_url(url: &str) -> &str { + if url.trim_end_matches('/') == LEGACY_PUBLIC_REGISTRY_URL { + CANONICAL_PUBLIC_REGISTRY_URL + } else { + url + } +} + pub fn registry_for(url: &str) -> Result> { + let url = canonical_registry_url(url); if url.starts_with("file://") { Ok(Box::new(FileRegistry::new(file_registry_path(url)?))) } else if url.starts_with("http://") || url.starts_with("https://") { @@ -169,6 +181,23 @@ pub fn registry_for(url: &str) -> Result> { } } +#[cfg(test)] +#[test] +fn legacy_public_registry_alias_uses_the_canonical_zpkg_edge() { + assert_eq!( + canonical_registry_url("https://registry.zpkg.net"), + "https://zpkg.net" + ); + assert_eq!( + canonical_registry_url("https://registry.zpkg.net/"), + "https://zpkg.net" + ); + assert_eq!( + canonical_registry_url("https://registry.example.test"), + "https://registry.example.test" + ); +} + /// Pick the highest stable version satisfying `req`. pub fn resolve_version(req: &VersionReq, versions: &[String]) -> Option { versions