-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: only examine base URL when matching package #13110
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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,6 +566,12 @@ mod tests { | |||
| assert!(PackageIdSpec::parse("https://example.com#foo@1.2") | ||||
| .unwrap() | ||||
| .matches(foo)); | ||||
| assert!(PackageIdSpec::parse("https://example.com/foo") | ||||
| .unwrap() | ||||
| .matches(foo)); | ||||
| assert!(PackageIdSpec::parse("https://example.com/foo#1.2.3") | ||||
| .unwrap() | ||||
|
Comment on lines
+569
to
573
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What situation are you running into these package id specs existing that they should match the given package id? From looking at the code, the implicit name is mostly to avoid redundancy, like if you depend on a package in the root of a git repo by the same name.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this issue: cargo info https://github.com/rust-lang/crates.io-index/clap
Updating crates.io index
error: could not find `https://github.com/rust-lang/crates.io-index/clap` in registry `https://github.com/rust-lang/crates.io-index`As you can see, it told me it could not find the clap crate from the crates.io. I think this was a bug because the source ID doesn't have the package name in its URL. We shouldn't directly compare it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you get that package id spec from? $ cargo pkgid clap
https://github.com/rust-lang/crates.io-index#clap@4.4.10
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. I copied it from here: cargo/src/cargo/core/package_id_spec.rs Line 41 in a5fa676
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I ask what is the difference between them? When to use the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how representative that example is of real world spec ids...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will take a look at the details of the |
||||
| .matches(foo)); | ||||
| assert!(!PackageIdSpec::parse("https://bob.com#foo@1.2") | ||||
| .unwrap() | ||||
| .matches(foo)); | ||||
|
|
||||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.