mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Assert that Dependency::name is never empty, prevent 'install ""' from crashing
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
This commit is contained in:
parent
c157d7dd7a
commit
81ed0620bc
@ -7,7 +7,7 @@ use cargo::util::ToUrl;
|
|||||||
pub fn cli() -> App {
|
pub fn cli() -> App {
|
||||||
subcommand("install")
|
subcommand("install")
|
||||||
.about("Install a Rust binary")
|
.about("Install a Rust binary")
|
||||||
.arg(Arg::with_name("crate").multiple(true))
|
.arg(Arg::with_name("crate").empty_values(false).multiple(true))
|
||||||
.arg(
|
.arg(
|
||||||
opt("version", "Specify a version to install from crates.io")
|
opt("version", "Specify a version to install from crates.io")
|
||||||
.alias("vers")
|
.alias("vers")
|
||||||
|
@ -185,6 +185,7 @@ impl Dependency {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_override(name: &str, source_id: &SourceId) -> Dependency {
|
pub fn new_override(name: &str, source_id: &SourceId) -> Dependency {
|
||||||
|
assert!(name.len() > 0);
|
||||||
Dependency {
|
Dependency {
|
||||||
inner: Rc::new(Inner {
|
inner: Rc::new(Inner {
|
||||||
name: InternedString::new(name),
|
name: InternedString::new(name),
|
||||||
|
@ -1476,3 +1476,14 @@ dependencies = [
|
|||||||
|
|
||||||
assert_that(cargo_process("install").arg("foo"), execs().with_status(0));
|
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",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -172,6 +172,13 @@ fn loc_names(names: &[(&'static str, &'static str)]) -> Vec<PackageId> {
|
|||||||
.collect()
|
.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]
|
#[test]
|
||||||
fn test_resolving_empty_dependency_list() {
|
fn test_resolving_empty_dependency_list() {
|
||||||
let res = resolve(&pkg_id("root"), Vec::new(), ®istry(vec![])).unwrap();
|
let res = resolve(&pkg_id("root"), Vec::new(), ®istry(vec![])).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user