Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow invalid dependency names through crate renaming #8090

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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