Skip to content

Commit

Permalink
Auto merge of #13152 - hi-rustin:rustin-patch-empty-name, r=epage
Browse files Browse the repository at this point in the history
Do not allow empty name in package ID spec
  • Loading branch information
bors committed Dec 13, 2023
2 parents 0e18edf + 1248522 commit 8412d30
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cargo/util_schemas/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ impl PackageIdSpec {
Some(version) => Some(version.parse::<PartialVersion>()?),
None => None,
};
if name.is_empty() {
bail!("package ID specification must have a name: `{spec}`");
}
validate_package_name(name, "pkgid", "")?;
Ok(PackageIdSpec {
name: String::from(name),
Expand Down Expand Up @@ -182,6 +185,10 @@ impl PackageIdSpec {
None => (String::from(path_name), None),
}
};
if name.is_empty() {
bail!("package ID specification must have a name: `{url}`");
}
validate_package_name(name.as_str(), "pkgid", "")?;
Ok(PackageIdSpec {
name,
version,
Expand Down Expand Up @@ -585,5 +592,8 @@ mod tests {
"sparse+https://github.com/rust-lang/cargo#0.52.0?branch=dev"
)
.is_err());
assert!(PackageIdSpec::parse("@1.2.3").is_err());
assert!(PackageIdSpec::parse("registry+https://github.com").is_err());
assert!(PackageIdSpec::parse("https://crates.io/1foo#1.2.3").is_err())
}
}

0 comments on commit 8412d30

Please sign in to comment.