Skip to content

Commit 1e6ed94

Browse files
committed
Auto merge of #8090 - mbStavola:invalid-dep-naming, r=alexcrichton
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.
2 parents da54d6b + fcff51b commit 1e6ed94

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/cargo/util/toml/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ impl TomlManifest {
10821082
};
10831083
for (n, v) in dependencies.iter() {
10841084
let dep = v.to_dependency(n, cx, kind)?;
1085+
validate_package_name(dep.name_in_toml().as_str(), "dependency name", "")?;
10851086
cx.deps.push(dep);
10861087
}
10871088

tests/testsuite/build.rs

+31
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,37 @@ required by package `foo v0.0.1 ([CWD])`
911911
.run();
912912
}
913913

914+
// Ensure that renamed deps have a valid name
915+
#[cargo_test]
916+
fn cargo_compile_with_invalid_dep_rename() {
917+
let p = project()
918+
.file(
919+
"Cargo.toml",
920+
r#"
921+
[package]
922+
name = "buggin"
923+
version = "0.1.0"
924+
925+
[dependencies]
926+
"haha this isn't a valid name 🐛" = { package = "libc", version = "0.1" }
927+
"#,
928+
)
929+
.file("src/main.rs", &main_file(r#""What's good?""#, &[]))
930+
.build();
931+
932+
p.cargo("build")
933+
.with_status(101)
934+
.with_stderr(
935+
"\
936+
error: failed to parse manifest at `[..]`
937+
938+
Caused by:
939+
invalid character ` ` in dependency name: `haha this isn't a valid name 🐛`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
940+
",
941+
)
942+
.run();
943+
}
944+
914945
#[cargo_test]
915946
fn cargo_compile_with_filename() {
916947
let p = project()

0 commit comments

Comments
 (0)