Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/cargo-util-schemas/src/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ impl PackageIdSpec {
Some(fragment) => match parse_spec(&fragment)? {
Some((name, ver)) => (name, ver),
None => {
if fragment.chars().next().unwrap().is_alphabetic() {
let Some(f) = fragment.chars().next() else {
return Err(PackageIdSpecError(ErrorKind::EmptyFragment));
};

if f.is_alphabetic() {
(String::from(fragment.as_str()), None)
} else {
let version = fragment.parse::<PartialVersion>()?;
Expand Down Expand Up @@ -322,6 +326,9 @@ enum ErrorKind {
#[error("package ID specification `{spec}` looks like a file path, maybe try {maybe_url}")]
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


#[error(transparent)]
NameValidation(#[from] crate::restricted_names::NameValidationError),

Expand Down Expand Up @@ -764,5 +771,6 @@ mod tests {
err!("@1.2.3", ErrorKind::NameValidation(_));
err!("registry+https://github.com", ErrorKind::NameValidation(_));
err!("https://crates.io/1foo#1.2.3", ErrorKind::NameValidation(_));
err!("https://example.com/foo#", ErrorKind::EmptyFragment);
Comment on lines 773 to +774
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);
}
}