Skip to content

Commit 696b054

Browse files
committed
tarball/manifest: Explicitly check that version field exists
1 parent ea73025 commit 696b054

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

crates/crates_io_tarball/src/manifest.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ pub fn validate_manifest(manifest: &Manifest) -> Result<(), Error> {
2424
}
2525

2626
pub fn validate_package(package: &Package) -> Result<(), Error> {
27+
// Check that the `version` field exists in the package table.
28+
let version = package
29+
.version
30+
.as_ref()
31+
.ok_or(Error::Other("missing field `version`".to_string()))?;
32+
2733
// These checks ensure that package field workspace inheritance has been
2834
// normalized by cargo before publishing.
2935
if package.edition.is_inherited()
3036
|| package.rust_version.is_inherited()
31-
|| package.version.is_inherited()
37+
|| version.is_inherited()
3238
|| package.authors.is_inherited()
3339
|| package.description.is_inherited()
3440
|| package.homepage.is_inherited()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
source: src/tests/krate/publish/manifest.rs
3-
expression: response.into_json()
3+
expression: response.json()
44
---
55
{
66
"errors": [
77
{
8-
"detail": "failed to parse `Cargo.toml` manifest file\n\nTOML parse error at line 1, column 1\n |\n1 | [package]\n | ^^^^^^^^^\nmissing field `version`\n"
8+
"detail": "failed to parse `Cargo.toml` manifest file\n\nmissing field `version`"
99
}
1010
]
1111
}

0 commit comments

Comments
 (0)