Skip to content
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
Copy Markdown
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
Copy Markdown
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#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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this issue:
0xPoe/cargo-information#57

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.

Copy link
Copy Markdown
Contributor

@epage epage Dec 5, 2023

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh. I copied it from here:

/// "https://crates.io/foo",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 "https://crates.io/foo"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder how representative that example is of real world spec ids...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will take a look at the details of the pkgid command. Thank you!

.matches(foo));
assert!(!PackageIdSpec::parse("https://bob.com#foo@1.2")
.unwrap()
.matches(foo));
Expand Down