From 7200646a9794468d466a65267d1a33ce872cfed6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 13 Dec 2023 10:15:57 -0600 Subject: [PATCH 1/5] test: Demonstrate existing empty name errors --- tests/testsuite/alt_registry.rs | 76 +++++++++++++++++ tests/testsuite/cargo_add/empty_dep_name/in | 1 + .../testsuite/cargo_add/empty_dep_name/mod.rs | 24 ++++++ .../cargo_add/empty_dep_name/out/Cargo.toml | 5 ++ .../cargo_add/empty_dep_name/stderr.log | 3 + .../cargo_add/empty_dep_name/stdout.log | 0 tests/testsuite/cargo_add/mod.rs | 1 + tests/testsuite/cargo_new/empty_name/in/.keep | 0 tests/testsuite/cargo_new/empty_name/mod.rs | 22 +++++ .../testsuite/cargo_new/empty_name/out/.keep | 0 .../testsuite/cargo_new/empty_name/stderr.log | 7 ++ .../testsuite/cargo_new/empty_name/stdout.log | 0 tests/testsuite/cargo_new/mod.rs | 1 + tests/testsuite/patch.rs | 83 +++++++++++++++++++ 14 files changed, 223 insertions(+) create mode 120000 tests/testsuite/cargo_add/empty_dep_name/in create mode 100644 tests/testsuite/cargo_add/empty_dep_name/mod.rs create mode 100644 tests/testsuite/cargo_add/empty_dep_name/out/Cargo.toml create mode 100644 tests/testsuite/cargo_add/empty_dep_name/stderr.log create mode 100644 tests/testsuite/cargo_add/empty_dep_name/stdout.log create mode 100644 tests/testsuite/cargo_new/empty_name/in/.keep create mode 100644 tests/testsuite/cargo_new/empty_name/mod.rs create mode 100644 tests/testsuite/cargo_new/empty_name/out/.keep create mode 100644 tests/testsuite/cargo_new/empty_name/stderr.log create mode 100644 tests/testsuite/cargo_new/empty_name/stdout.log diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index d6d7dd531cc..c2aa6e71a62 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1546,3 +1546,79 @@ or use environment variable CARGO_REGISTRY_TOKEN", ) .run(); } + +#[cargo_test] +fn config_empty_registry_name() { + let _ = RegistryBuilder::new() + .no_configure_token() + .alternative() + .build(); + let p = project() + .file("src/lib.rs", "") + .file( + ".cargo/config.toml", + "[registry.''] + ", + ) + .build(); + + p.cargo("publish") + .arg("--registry") + .arg("") + .with_status(101) + .with_stderr( + "\ +[ERROR] registry index was not found in any configuration: ``", + ) + .run(); +} + +#[cargo_test] +fn empty_registry_flag() { + let p = project().file("src/lib.rs", "").build(); + + p.cargo("publish") + .arg("--registry") + .arg("") + .with_status(101) + .with_stderr( + "\ +[ERROR] registry index was not found in any configuration: ``", + ) + .run(); +} + +#[cargo_test] +fn empty_dependency_registry() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = { version = "0.1.0", registry = "" } + "#, + ) + .file( + "src/lib.rs", + " + extern crate bar; + pub fn f() { bar::bar(); } + ", + ) + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + registry index was not found in any configuration: ``", + ) + .run(); +} diff --git a/tests/testsuite/cargo_add/empty_dep_name/in b/tests/testsuite/cargo_add/empty_dep_name/in new file mode 120000 index 00000000000..6c6a27fcfb5 --- /dev/null +++ b/tests/testsuite/cargo_add/empty_dep_name/in @@ -0,0 +1 @@ +../add-basic.in \ No newline at end of file diff --git a/tests/testsuite/cargo_add/empty_dep_name/mod.rs b/tests/testsuite/cargo_add/empty_dep_name/mod.rs new file mode 100644 index 00000000000..d7044ee1178 --- /dev/null +++ b/tests/testsuite/cargo_add/empty_dep_name/mod.rs @@ -0,0 +1,24 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +use cargo_test_support::curr_dir; + +#[cargo_test] +fn case() { + cargo_test_support::registry::init(); + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("add") + .arg_line("@1.2.3") + .current_dir(cwd) + .assert() + .failure() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/tests/testsuite/cargo_add/empty_dep_name/out/Cargo.toml b/tests/testsuite/cargo_add/empty_dep_name/out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/testsuite/cargo_add/empty_dep_name/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/testsuite/cargo_add/empty_dep_name/stderr.log b/tests/testsuite/cargo_add/empty_dep_name/stderr.log new file mode 100644 index 00000000000..6fd5e42b7e0 --- /dev/null +++ b/tests/testsuite/cargo_add/empty_dep_name/stderr.log @@ -0,0 +1,3 @@ +thread 'main' panicked at src/cargo/core/dependency.rs:164:9: +assertion failed: !name.is_empty() +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/tests/testsuite/cargo_add/empty_dep_name/stdout.log b/tests/testsuite/cargo_add/empty_dep_name/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs index 47f5ba0e574..653c2db94cb 100644 --- a/tests/testsuite/cargo_add/mod.rs +++ b/tests/testsuite/cargo_add/mod.rs @@ -17,6 +17,7 @@ mod dev; mod dev_build_conflict; mod dev_prefer_existing_version; mod dry_run; +mod empty_dep_name; mod empty_dep_table; mod features; mod features_activated_over_limit; diff --git a/tests/testsuite/cargo_new/empty_name/in/.keep b/tests/testsuite/cargo_new/empty_name/in/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_new/empty_name/mod.rs b/tests/testsuite/cargo_new/empty_name/mod.rs new file mode 100644 index 00000000000..9edf84afeee --- /dev/null +++ b/tests/testsuite/cargo_new/empty_name/mod.rs @@ -0,0 +1,22 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::curr_dir; +use cargo_test_support::CargoCommand; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(curr_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("new") + .args(["foo", "--name", ""]) + .current_dir(cwd) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); + + assert_ui().subset_matches(curr_dir!().join("out"), &project_root); +} diff --git a/tests/testsuite/cargo_new/empty_name/out/.keep b/tests/testsuite/cargo_new/empty_name/out/.keep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_new/empty_name/stderr.log b/tests/testsuite/cargo_new/empty_name/stderr.log new file mode 100644 index 00000000000..8e845b6e448 --- /dev/null +++ b/tests/testsuite/cargo_new/empty_name/stderr.log @@ -0,0 +1,7 @@ +warning: compiling this new package may not work due to invalid workspace configuration + +failed to parse manifest at `[ROOT]/case/foo/Cargo.toml` + +Caused by: + package name cannot be an empty string + Created binary (application) `` package diff --git a/tests/testsuite/cargo_new/empty_name/stdout.log b/tests/testsuite/cargo_new/empty_name/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_new/mod.rs b/tests/testsuite/cargo_new/mod.rs index da030440975..806bd2ec375 100644 --- a/tests/testsuite/cargo_new/mod.rs +++ b/tests/testsuite/cargo_new/mod.rs @@ -4,6 +4,7 @@ mod add_members_to_workspace_with_absolute_package_path; mod add_members_to_workspace_with_empty_members; mod add_members_to_workspace_with_exclude_list; mod add_members_to_workspace_with_members_glob; +mod empty_name; mod help; mod inherit_workspace_lints; mod inherit_workspace_package_table; diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index a467f60b5a2..a4522e82219 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -2700,3 +2700,86 @@ perhaps a crate was updated and forgotten to be re-vendored?"#, ) .run(); } + +#[cargo_test] +fn from_config_empty() { + Package::new("bar", "0.1.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1.0" + "#, + ) + .file( + ".cargo/config.toml", + r#" + [patch.''] + bar = { path = 'bar' } + "#, + ) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1")) + .file("bar/src/lib.rs", r#""#) + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + "\ +[ERROR] [patch] entry `` should be a URL or registry name + +Caused by: + invalid url ``: relative URL without a base +", + ) + .run(); +} + +#[cargo_test] +fn from_manifest_empty() { + Package::new("bar", "0.1.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = "0.1.0" + + [patch.''] + bar = { path = 'bar' } + "#, + ) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1")) + .file("bar/src/lib.rs", r#""#) + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + [patch] entry `` should be a URL or registry name + +Caused by: + invalid url ``: relative URL without a base +", + ) + .run(); +} From 179135368991f442dc7770bc0a0a0ba044368444 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 13 Dec 2023 09:40:32 -0600 Subject: [PATCH 2/5] fix!: Disallow empty registry names This was allowed when switching from `toml` v0.5 to `toml_edit` which started allowing empty keys when parsing TOML. This mirrors the change we made for disallowing empty feature names in #12928. --- src/cargo/util/command_prelude.rs | 6 ++++++ src/cargo/util/config/mod.rs | 3 +++ tests/testsuite/alt_registry.rs | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 3e236a6f735..6ce6161be40 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -833,6 +833,9 @@ Run `{cmd}` to see possible targets." (None, None) => config.default_registry()?.map(RegistryOrIndex::Registry), (None, Some(i)) => Some(RegistryOrIndex::Index(i.into_url()?)), (Some(r), None) => { + if r.is_empty() { + bail!("registry name cannot be empty"); + } restricted_names::validate_package_name(r, "registry name", "")?; Some(RegistryOrIndex::Registry(r.to_string())) } @@ -848,6 +851,9 @@ Run `{cmd}` to see possible targets." match self._value_of("registry").map(|s| s.to_string()) { None => config.default_registry(), Some(registry) => { + if registry.is_empty() { + bail!("registry name cannot be empty"); + } restricted_names::validate_package_name(®istry, "registry name", "")?; Ok(Some(registry)) } diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index c0dd42d39b8..cf70eda91ee 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1551,6 +1551,9 @@ impl Config { /// Gets the index for a registry. pub fn get_registry_index(&self, registry: &str) -> CargoResult { + if registry.is_empty() { + bail!("registry name cannot be empty"); + } validate_package_name(registry, "registry name", "")?; if let Some(index) = self.get_string(&format!("registries.{}.index", registry))? { self.resolve_registry_index(&index).with_context(|| { diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index c2aa6e71a62..8982b1941a7 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1568,7 +1568,7 @@ fn config_empty_registry_name() { .with_status(101) .with_stderr( "\ -[ERROR] registry index was not found in any configuration: ``", +[ERROR] registry name cannot be empty", ) .run(); } @@ -1583,7 +1583,7 @@ fn empty_registry_flag() { .with_status(101) .with_stderr( "\ -[ERROR] registry index was not found in any configuration: ``", +[ERROR] registry name cannot be empty", ) .run(); } @@ -1618,7 +1618,7 @@ fn empty_dependency_registry() { [ERROR] failed to parse manifest at `[CWD]/Cargo.toml` Caused by: - registry index was not found in any configuration: ``", + registry name cannot be empty", ) .run(); } From 9de03cd1fd117cc601052bd6f527e1fd740f024c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 13 Dec 2023 09:50:07 -0600 Subject: [PATCH 3/5] fix(add): Catch empty dep name early --- src/cargo/ops/cargo_add/crate_spec.rs | 4 ++++ tests/testsuite/cargo_add/empty_dep_name/stderr.log | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_add/crate_spec.rs b/src/cargo/ops/cargo_add/crate_spec.rs index 4cf6f484a32..4d0f067f6cf 100644 --- a/src/cargo/ops/cargo_add/crate_spec.rs +++ b/src/cargo/ops/cargo_add/crate_spec.rs @@ -1,5 +1,6 @@ //! Crate name parsing. +use anyhow::bail; use anyhow::Context as _; use super::Dependency; @@ -28,6 +29,9 @@ impl CrateSpec { .map(|(n, v)| (n, Some(v))) .unwrap_or((pkg_id, None)); + if name.is_empty() { + bail!("dependency name cannot be empty"); + } validate_package_name(name, "dependency name", "")?; if let Some(version) = version { diff --git a/tests/testsuite/cargo_add/empty_dep_name/stderr.log b/tests/testsuite/cargo_add/empty_dep_name/stderr.log index 6fd5e42b7e0..1bb057cd14d 100644 --- a/tests/testsuite/cargo_add/empty_dep_name/stderr.log +++ b/tests/testsuite/cargo_add/empty_dep_name/stderr.log @@ -1,3 +1 @@ -thread 'main' panicked at src/cargo/core/dependency.rs:164:9: -assertion failed: !name.is_empty() -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +error: dependency name cannot be empty From 2db5c9dd59673662bf835929bd3156b8f0a66cf4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 13 Dec 2023 09:56:30 -0600 Subject: [PATCH 4/5] fix(new): Catch empty package names earlier --- src/cargo/ops/cargo_new.rs | 5 ++++- tests/testsuite/cargo_new/empty_name/mod.rs | 2 +- tests/testsuite/cargo_new/empty_name/stderr.log | 8 +------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 1c06b5f8258..b68baaed4a6 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -4,7 +4,7 @@ use crate::util::important_paths::find_root_manifest_for_wd; use crate::util::toml_mut::is_sorted; use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo}; use crate::util::{restricted_names, Config}; -use anyhow::{anyhow, Context}; +use anyhow::{anyhow, bail, Context}; use cargo_util::paths::{self, write_atomic}; use serde::de; use serde::Deserialize; @@ -197,6 +197,9 @@ fn check_name( } help }; + if name.is_empty() { + bail!("package name cannot be empty"); + } restricted_names::validate_package_name(name, "package name", &bin_help())?; if restricted_names::is_keyword(name) { diff --git a/tests/testsuite/cargo_new/empty_name/mod.rs b/tests/testsuite/cargo_new/empty_name/mod.rs index 9edf84afeee..a7d56630fb5 100644 --- a/tests/testsuite/cargo_new/empty_name/mod.rs +++ b/tests/testsuite/cargo_new/empty_name/mod.rs @@ -14,7 +14,7 @@ fn case() { .args(["foo", "--name", ""]) .current_dir(cwd) .assert() - .success() + .failure() .stdout_matches_path(curr_dir!().join("stdout.log")) .stderr_matches_path(curr_dir!().join("stderr.log")); diff --git a/tests/testsuite/cargo_new/empty_name/stderr.log b/tests/testsuite/cargo_new/empty_name/stderr.log index 8e845b6e448..d9547a42acf 100644 --- a/tests/testsuite/cargo_new/empty_name/stderr.log +++ b/tests/testsuite/cargo_new/empty_name/stderr.log @@ -1,7 +1 @@ -warning: compiling this new package may not work due to invalid workspace configuration - -failed to parse manifest at `[ROOT]/case/foo/Cargo.toml` - -Caused by: - package name cannot be an empty string - Created binary (application) `` package +error: package name cannot be empty From a383185c38a9c076796ce4e6f922776053fae056 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 13 Dec 2023 09:36:14 -0600 Subject: [PATCH 5/5] refactor: Centralize empty name check --- src/cargo/ops/cargo_add/crate_spec.rs | 4 ---- src/cargo/ops/cargo_new.rs | 5 +---- src/cargo/util/command_prelude.rs | 6 ------ src/cargo/util/config/mod.rs | 3 --- src/cargo/util/restricted_names.rs | 4 ++++ src/cargo/util/toml/mod.rs | 4 ---- src/cargo/util_schemas/core/package_id_spec.rs | 6 ------ tests/testsuite/build.rs | 2 +- 8 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/cargo/ops/cargo_add/crate_spec.rs b/src/cargo/ops/cargo_add/crate_spec.rs index 4d0f067f6cf..4cf6f484a32 100644 --- a/src/cargo/ops/cargo_add/crate_spec.rs +++ b/src/cargo/ops/cargo_add/crate_spec.rs @@ -1,6 +1,5 @@ //! Crate name parsing. -use anyhow::bail; use anyhow::Context as _; use super::Dependency; @@ -29,9 +28,6 @@ impl CrateSpec { .map(|(n, v)| (n, Some(v))) .unwrap_or((pkg_id, None)); - if name.is_empty() { - bail!("dependency name cannot be empty"); - } validate_package_name(name, "dependency name", "")?; if let Some(version) = version { diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index b68baaed4a6..1c06b5f8258 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -4,7 +4,7 @@ use crate::util::important_paths::find_root_manifest_for_wd; use crate::util::toml_mut::is_sorted; use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo}; use crate::util::{restricted_names, Config}; -use anyhow::{anyhow, bail, Context}; +use anyhow::{anyhow, Context}; use cargo_util::paths::{self, write_atomic}; use serde::de; use serde::Deserialize; @@ -197,9 +197,6 @@ fn check_name( } help }; - if name.is_empty() { - bail!("package name cannot be empty"); - } restricted_names::validate_package_name(name, "package name", &bin_help())?; if restricted_names::is_keyword(name) { diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 6ce6161be40..3e236a6f735 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -833,9 +833,6 @@ Run `{cmd}` to see possible targets." (None, None) => config.default_registry()?.map(RegistryOrIndex::Registry), (None, Some(i)) => Some(RegistryOrIndex::Index(i.into_url()?)), (Some(r), None) => { - if r.is_empty() { - bail!("registry name cannot be empty"); - } restricted_names::validate_package_name(r, "registry name", "")?; Some(RegistryOrIndex::Registry(r.to_string())) } @@ -851,9 +848,6 @@ Run `{cmd}` to see possible targets." match self._value_of("registry").map(|s| s.to_string()) { None => config.default_registry(), Some(registry) => { - if registry.is_empty() { - bail!("registry name cannot be empty"); - } restricted_names::validate_package_name(®istry, "registry name", "")?; Ok(Some(registry)) } diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index cf70eda91ee..c0dd42d39b8 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1551,9 +1551,6 @@ impl Config { /// Gets the index for a registry. pub fn get_registry_index(&self, registry: &str) -> CargoResult { - if registry.is_empty() { - bail!("registry name cannot be empty"); - } validate_package_name(registry, "registry name", "")?; if let Some(index) = self.get_string(&format!("registries.{}.index", registry))? { self.resolve_registry_index(&index).with_context(|| { diff --git a/src/cargo/util/restricted_names.rs b/src/cargo/util/restricted_names.rs index f61249775d3..df0152ecb1e 100644 --- a/src/cargo/util/restricted_names.rs +++ b/src/cargo/util/restricted_names.rs @@ -43,6 +43,10 @@ pub fn is_conflicting_artifact_name(name: &str) -> bool { /// elsewhere. `cargo new` has a few restrictions, such as checking for /// reserved names. crates.io has even more restrictions. pub fn validate_package_name(name: &str, what: &str, help: &str) -> CargoResult<()> { + if name.is_empty() { + bail!("{what} cannot be empty"); + } + let mut chars = name.chars(); if let Some(ch) = chars.next() { if ch.is_digit(10) { diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 6824cb5f5c7..9439ca9179e 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -480,10 +480,6 @@ pub fn to_real_manifest( }; let package_name = package.name.trim(); - if package_name.is_empty() { - bail!("package name cannot be an empty string") - } - validate_package_name(package_name, "package name", "")?; let resolved_path = package_root.join("Cargo.toml"); diff --git a/src/cargo/util_schemas/core/package_id_spec.rs b/src/cargo/util_schemas/core/package_id_spec.rs index b5d2a3db223..07d1fb5ee9b 100644 --- a/src/cargo/util_schemas/core/package_id_spec.rs +++ b/src/cargo/util_schemas/core/package_id_spec.rs @@ -97,9 +97,6 @@ impl PackageIdSpec { Some(version) => Some(version.parse::()?), 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), @@ -185,9 +182,6 @@ 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, diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 250aeb08512..13553671e3c 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -460,7 +460,7 @@ fn cargo_compile_with_empty_package_name() { [ERROR] failed to parse manifest at `[..]` Caused by: - package name cannot be an empty string + package name cannot be empty ", ) .run();