Skip to content

Commit

Permalink
Auto merge of #8090 - mbStavola:invalid-dep-naming, r=alexcrichton
Browse files Browse the repository at this point in the history
Disallow invalid dependency names through crate renaming

resolves #6656

As suggested in the issue, I simply checked the dep names by calling `validate_package_name` on the dependencies during the TOML deserialization process.

It might be a bit too strict (and sudden) to error out in this case, so it might be best to convert this into a warning instead. However, this _is_ pretty invalid behavior so I'm not too sure really.
  • Loading branch information
bors committed Apr 9, 2020
2 parents da54d6b + fcff51b commit 1e6ed94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ impl TomlManifest {
};
for (n, v) in dependencies.iter() {
let dep = v.to_dependency(n, cx, kind)?;
validate_package_name(dep.name_in_toml().as_str(), "dependency name", "")?;
cx.deps.push(dep);
}

Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,37 @@ required by package `foo v0.0.1 ([CWD])`
.run();
}

// Ensure that renamed deps have a valid name
#[cargo_test]
fn cargo_compile_with_invalid_dep_rename() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "buggin"
version = "0.1.0"
[dependencies]
"haha this isn't a valid name 🐛" = { package = "libc", version = "0.1" }
"#,
)
.file("src/main.rs", &main_file(r#""What's good?""#, &[]))
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at `[..]`
Caused by:
invalid character ` ` in dependency name: `haha this isn't a valid name 🐛`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
",
)
.run();
}

#[cargo_test]
fn cargo_compile_with_filename() {
let p = project()
Expand Down

0 comments on commit 1e6ed94

Please sign in to comment.