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

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Dec 5, 2023

What does this PR try to resolve?

close Rustin170506/cargo-information#57

We should not directly compare the package spec URL with the source ID URL because the package spec URL contains the package's name in the URL.

For example:

https://github.com/rust-lang/crates.io-index/clap

  1. spec URL: Url { scheme: "https", cannot_be_a_base: false, username: ", password: None, host: Some(Domain("github.com")), port: None, path: "/rust-lang/crates.io-index/clap", query: None, fragment: None }
  2. source id URL: Url { scheme: "https", cannot_be_a_base: false, username: ", password: None, host: Some(Domain("github.com")), port: None, path: "/rust-lang/crates.io-index", query: None, fragment: None }

How should we test and review this PR?

Could you check the unit tests? Before the fix, it could fail.

Additional information

Do we need to change the URL itself instead of the matching process?

@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2023

r? @epage

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 5, 2023
@epage epage changed the title test: add more cases for URL package ID matching fix: only examine base URL when matching package Dec 5, 2023
Comment on lines +184 to +199
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 {
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.

Comment on lines 569 to 573
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()
Copy link
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
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:
Rustin170506/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
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#[email protected]

Copy link
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
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
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
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!

@bors
Copy link
Contributor

bors commented Dec 8, 2023

☔ The latest upstream changes (presumably #13128) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL package not works
4 participants