Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only examine base URL when matching package #13110

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/cargo/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment on lines +184 to +199
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its correct to completely ignore paths within the URLs, like with git sources.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I found it from the failed CI. We also support file URLs.

return false;
}
}
Expand Down Expand Up @@ -551,6 +566,12 @@ mod tests {
assert!(PackageIdSpec::parse("https://example.com#[email protected]")
.unwrap()
.matches(foo));
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#[email protected]")
.unwrap()
.matches(foo));
Expand Down
Loading