From d2b7d4a0d71ef11fa30944f08f2703779b0b6f1e Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 5 Dec 2023 09:50:56 +0800 Subject: [PATCH 1/2] test: add more cases for URL package ID matching Signed-off-by: hi-rustin --- src/cargo/core/package_id_spec.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index c617c1f7ab0..5718e93454f 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -551,6 +551,13 @@ mod tests { assert!(PackageIdSpec::parse("https://example.com#foo@1.2") .unwrap() .matches(foo)); + // FIXME: The two tests below need to be corrected or adjusted - they should be passing. + assert!(!PackageIdSpec::parse("https://example.com/foo") + .unwrap() + .matches(foo)); + assert!(!PackageIdSpec::parse("https://example.com/foo#1.2.3") + .unwrap() + .matches(foo)); assert!(!PackageIdSpec::parse("https://bob.com#foo@1.2") .unwrap() .matches(foo)); From 36f72532e880f32c467acd7676f8c53b92189439 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 5 Dec 2023 10:01:38 +0800 Subject: [PATCH 2/2] fix: only examine base URL when matching package Signed-off-by: hi-rustin --- src/cargo/core/package_id_spec.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index 5718e93454f..cf00c9bcf21 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -181,7 +181,22 @@ impl PackageIdSpec { } if let Some(u) = &self.url { - if u != package_id.source_id().url() { + let package_base_url = format!( + "{}://{}", + u.scheme(), + u.host_str().expect("package spec url should have a host") + ); + let source_id = package_id.source_id(); + let source_id_url = source_id.url(); + let source_id_base_url = format!( + "{}://{}", + source_id_url.scheme(), + source_id_url + .host_str() + .expect("source id url should have a host") + ); + // Examine only the base URL, as the package spec URL might include a package name within its path. + if package_base_url != source_id_base_url { return false; } } @@ -551,11 +566,10 @@ mod tests { assert!(PackageIdSpec::parse("https://example.com#foo@1.2") .unwrap() .matches(foo)); - // FIXME: The two tests below need to be corrected or adjusted - they should be passing. - assert!(!PackageIdSpec::parse("https://example.com/foo") + assert!(PackageIdSpec::parse("https://example.com/foo") .unwrap() .matches(foo)); - assert!(!PackageIdSpec::parse("https://example.com/foo#1.2.3") + assert!(PackageIdSpec::parse("https://example.com/foo#1.2.3") .unwrap() .matches(foo)); assert!(!PackageIdSpec::parse("https://bob.com#foo@1.2")