An explicit `cargo install ""` would cause clap to pass an empty crate-name,
leading to a panic(). We now assert() that Dependency::name is never the
empty string and prevent the situation in the first place by not allowing
the crate-name to be empty for `install`.
Fixes #5229
pub fn cli() -> App {
subcommand("install")
.about("Install a Rust binary")
- .arg(Arg::with_name("crate").multiple(true))
+ .arg(Arg::with_name("crate").empty_values(false).multiple(true))
.arg(
opt("version", "Specify a version to install from crates.io")
.alias("vers")
}
pub fn new_override(name: &str, source_id: &SourceId) -> Dependency {
+ assert!(name.len() > 0);
Dependency {
inner: Rc::new(Inner {
name: InternedString::new(name),
assert_that(cargo_process("install").arg("foo"), execs().with_status(0));
}
+
+#[test]
+fn install_empty_argument() {
+ // Bug 5229
+ assert_that(
+ cargo_process("install").arg(""),
+ execs().with_status(1).with_stderr_contains(
+ "[ERROR] The argument '<crate>...' requires a value but none was supplied",
+ ),
+ );
+}
.collect()
}
+#[test]
+#[should_panic(expected = "assertion failed: name.len() > 0")]
+fn test_dependency_with_empty_name() {
+ // Bug 5229, dependency-names must not be empty
+ "".to_dep();
+}
+
#[test]
fn test_resolving_empty_dependency_list() {
let res = resolve(&pkg_id("root"), Vec::new(), ®istry(vec![])).unwrap();