Skip to content

Commit

Permalink
fix: validate package name from URL
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Dec 11, 2023
1 parent 4dc1178 commit 1248522
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cargo/util_schemas/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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 @@ -601,7 +605,7 @@ mod tests {
)
.is_err());
assert!(PackageIdSpec::parse("@1.2.3").is_err());
assert!(PackageIdSpec::parse("registry+https://github.com").is_ok());
assert!(PackageIdSpec::parse("https://crates.io/1foo#1.2.3").is_ok())
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 1248522

Please sign in to comment.