Skip to content

Commit bba3417

Browse files
committed
Move the check.
1 parent c05ef02 commit bba3417

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

crates/crates_io_tarball/src/manifest.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ pub fn validate_manifest(manifest: &Manifest) -> Result<(), Error> {
77
// does not accept workspace manifests.
88
let package = package.ok_or(Error::Other("missing field `package`".to_string()))?;
99

10+
// We don't want to allow [patch] sections in manifests at all.
11+
if matches!(&manifest.patch, Some(patch) if !patch.is_empty()) {
12+
return Err(Error::Other(
13+
"crates cannot be published with `[patch]` tables".to_string(),
14+
));
15+
}
16+
1017
validate_package(package)?;
1118

1219
// These checks ensure that dependency workspace inheritance has been

src/controllers/krate/publish.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,6 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
342342
validate_dependency(dep)?;
343343
}
344344

345-
// We don't want to allow [patch] sections in manifests at all.
346-
if matches!(&tarball_info.manifest.patch, Some(patch) if !patch.is_empty()) {
347-
return Err(bad_request(
348-
"crates.io does not allow crates to be published with `[patch]` sections in their manifests.",
349-
));
350-
}
351-
352345
let api_token_id = auth.api_token_id();
353346
let user = auth.user();
354347

src/tests/krate/publish/dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ async fn new_krate_with_patch() {
313313

314314
let response = token.publish_crate(crate_to_publish).await;
315315
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
316-
assert_snapshot!(response.text(), @r###"{"errors":[{"detail":"crates.io does not allow crates to be published with `[patch]` sections in their manifests."}]}"###);
316+
assert_snapshot!(response.text(), @r###"{"errors":[{"detail":"failed to parse `Cargo.toml` manifest file\n\ncrates cannot be published with `[patch]` tables"}]}"###);
317317
assert_that!(app.stored_files().await, empty());
318318
}
319319

0 commit comments

Comments
 (0)