Skip to content

fix: Avoid panic for package specs with an empty fragment#16754

Merged
0xPoe merged 2 commits intorust-lang:masterfrom
Pyr0de:issue-16731
Mar 15, 2026
Merged

fix: Avoid panic for package specs with an empty fragment#16754
0xPoe merged 2 commits intorust-lang:masterfrom
Pyr0de:issue-16731

Conversation

@Pyr0de
Copy link
Contributor

@Pyr0de Pyr0de commented Mar 15, 2026

What does this PR try to resolve?

Fixes #16731

PackageIdSpec::parse panics on URL package specs with an empty fragment (...#)
This change would return PackageIdSpecError(ErrorKind::EmptyFragment) instead of panicing

How to test and review this PR?

Earlier the following code would panic

let _ = PackageIdSpec::parse("https://example.com/foo#");

but now it should return an error

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2026

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo
@Pyr0de Pyr0de changed the title Issue 16731 fix: Avoid panic for package specs with an empty fragment Mar 15, 2026
Copy link
Member

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

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

MaybeFilePath { spec: String, maybe_url: String },

#[error("pkgid url cannot have an empty fragment")]
EmptyFragment,
Copy link
Member

Choose a reason for hiding this comment

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

This is a non-public error kind, so I believe this is acceptable.
cc: @weihanglo Not sure if you have any thoughts on it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah should be good

Comment on lines 773 to +775
err!("https://crates.io/1foo#1.2.3", ErrorKind::NameValidation(_));

err!("https://example.com/foo#", ErrorKind::EmptyFragment);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err!("https://crates.io/1foo#1.2.3", ErrorKind::NameValidation(_));
err!("https://example.com/foo#", ErrorKind::EmptyFragment);
err!("https://crates.io/1foo#1.2.3", ErrorKind::NameValidation(_));
err!("https://example.com/foo#", ErrorKind::EmptyFragment);
@Pyr0de Pyr0de requested a review from 0xPoe March 15, 2026 16:17
@0xPoe 0xPoe added this pull request to the merge queue Mar 15, 2026
Merged via the queue into rust-lang:master with commit 592bc40 Mar 15, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 15, 2026
@Pyr0de Pyr0de deleted the issue-16731 branch March 16, 2026 14:29
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Mar 20, 2026
Update cargo submodule 13 commits in cbb9bb8bd0fb272b1be0d63a010701ecb3d1d6d3..d81735547e5f2844322f36380ab66f549cda11b9 2026-03-13 14:34:16 +0000 to 2026-03-20 13:20:51 +0000 - cargo clean: Validate that target_dir is not a file (rust-lang/cargo#16765) - fix: fetching non-standard git refspecs on non-github repos (rust-lang/cargo#16768) - Update tar to 0.4.45 (rust-lang/cargo#16771) - chore: Remove edition_lint_opts from Lint (rust-lang/cargo#16762) - refactor: split out several smaller changes to prepare for async http (rust-lang/cargo#16763) - fix(compile): Make build.warnings ignore non-local deps (rust-lang/cargo#16760) - fix: detect circular publish dependency cycle in workspace publish (rust-lang/cargo#16722) - refactor(shell): Pull out term integration into `anstyle-progress` (rust-lang/cargo#16757) - test: reproduce rustfix panic on overlapping suggestions (rust-lang/cargo#16705) - fix: Avoid panic for package specs with an empty fragment (rust-lang/cargo#16754) - refactor(registry): avoid dynamic dispatch for Registry trait (rust-lang/cargo#16752) - refactor(shell): Pull out hyperlink logic into anstyle-hyperlink (rust-lang/cargo#16749) - refactor(install): Remove dead code (rust-lang/cargo#16718) r? ghost
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Mar 21, 2026
Update cargo submodule 14 commits in cbb9bb8bd0fb272b1be0d63a010701ecb3d1d6d3..e84cb639edfea2c42efd563b72a9be0cc5de6523 2026-03-13 14:34:16 +0000 to 2026-03-21 01:27:07 +0000 - Fix symlink_and_directory when running in a long target dir name (rust-lang/cargo#16775) - cargo clean: Validate that target_dir is not a file (rust-lang/cargo#16765) - fix: fetching non-standard git refspecs on non-github repos (rust-lang/cargo#16768) - Update tar to 0.4.45 (rust-lang/cargo#16771) - chore: Remove edition_lint_opts from Lint (rust-lang/cargo#16762) - refactor: split out several smaller changes to prepare for async http (rust-lang/cargo#16763) - fix(compile): Make build.warnings ignore non-local deps (rust-lang/cargo#16760) - fix: detect circular publish dependency cycle in workspace publish (rust-lang/cargo#16722) - refactor(shell): Pull out term integration into `anstyle-progress` (rust-lang/cargo#16757) - test: reproduce rustfix panic on overlapping suggestions (rust-lang/cargo#16705) - fix: Avoid panic for package specs with an empty fragment (rust-lang/cargo#16754) - refactor(registry): avoid dynamic dispatch for Registry trait (rust-lang/cargo#16752) - refactor(shell): Pull out hyperlink logic into anstyle-hyperlink (rust-lang/cargo#16749) - refactor(install): Remove dead code (rust-lang/cargo#16718)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants