diff --git a/crates/cache-key/src/canonical_url.rs b/crates/cache-key/src/canonical_url.rs index 36c15dae4..b45e33747 100644 --- a/crates/cache-key/src/canonical_url.rs +++ b/crates/cache-key/src/canonical_url.rs @@ -21,6 +21,11 @@ impl CanonicalUrl { pub fn new(url: &Url) -> Self { let mut url = url.clone(); + // If the URL cannot be a base, then it's not a valid URL anyway. + if url.cannot_be_a_base() { + return Self(url); + } + // Strip a trailing slash. if url.path().ends_with('/') { url.path_segments_mut().unwrap().pop_if_empty(); @@ -194,6 +199,12 @@ mod tests { )?, ); + // Two URLs that cannot be a base should be considered equal. + assert_eq!( + CanonicalUrl::parse("git+https:://github.com/pypa/sample-namespace-packages.git")?, + CanonicalUrl::parse("git+https:://github.com/pypa/sample-namespace-packages.git")?, + ); + Ok(()) }