Skip to content

Commit fed84e0

Browse files
committed
Auto merge of #12928 - hi-rustin:rustin-patch-feature-name, r=epage
Do not allow empty feature name
2 parents 4270265 + d618164 commit fed84e0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Diff for: src/cargo/core/summary.rs

+4
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ impl fmt::Display for FeatureValue {
431431
pub type FeatureMap = BTreeMap<InternedString, Vec<FeatureValue>>;
432432

433433
fn validate_feature_name(pkg_id: PackageId, name: &str) -> CargoResult<()> {
434+
if name.is_empty() {
435+
bail!("feature name cannot be empty");
436+
}
434437
let mut chars = name.chars();
435438
if let Some(ch) = chars.next() {
436439
if !(unicode_xid::UnicodeXID::is_xid_start(ch) || ch == '_' || ch.is_digit(10)) {
@@ -488,5 +491,6 @@ mod tests {
488491
assert!(validate_feature_name(pkg_id, "?foo").is_err());
489492
assert!(validate_feature_name(pkg_id, "ⒶⒷⒸ").is_err());
490493
assert!(validate_feature_name(pkg_id, "a¼").is_err());
494+
assert!(validate_feature_name(pkg_id, "").is_err());
491495
}
492496
}

Diff for: tests/testsuite/features.rs

+31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ Caused by:
3535
.run();
3636
}
3737

38+
#[cargo_test]
39+
fn empty_feature_name() {
40+
let p = project()
41+
.file(
42+
"Cargo.toml",
43+
r#"
44+
[package]
45+
name = "foo"
46+
version = "0.0.1"
47+
authors = []
48+
49+
[features]
50+
"" = []
51+
"#,
52+
)
53+
.file("src/main.rs", "")
54+
.build();
55+
56+
p.cargo("check")
57+
.with_status(101)
58+
.with_stderr(
59+
"\
60+
[ERROR] failed to parse manifest at `[..]`
61+
62+
Caused by:
63+
feature name cannot be empty
64+
",
65+
)
66+
.run();
67+
}
68+
3869
#[cargo_test]
3970
fn same_name() {
4071
// Feature with the same name as a dependency.

0 commit comments

Comments
 (0)