File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -431,6 +431,9 @@ impl fmt::Display for FeatureValue {
431
431
pub type FeatureMap = BTreeMap < InternedString , Vec < FeatureValue > > ;
432
432
433
433
fn validate_feature_name ( pkg_id : PackageId , name : & str ) -> CargoResult < ( ) > {
434
+ if name. is_empty ( ) {
435
+ bail ! ( "feature name cannot be empty" ) ;
436
+ }
434
437
let mut chars = name. chars ( ) ;
435
438
if let Some ( ch) = chars. next ( ) {
436
439
if !( unicode_xid:: UnicodeXID :: is_xid_start ( ch) || ch == '_' || ch. is_digit ( 10 ) ) {
@@ -488,5 +491,6 @@ mod tests {
488
491
assert ! ( validate_feature_name( pkg_id, "?foo" ) . is_err( ) ) ;
489
492
assert ! ( validate_feature_name( pkg_id, "ⒶⒷⒸ" ) . is_err( ) ) ;
490
493
assert ! ( validate_feature_name( pkg_id, "a¼" ) . is_err( ) ) ;
494
+ assert ! ( validate_feature_name( pkg_id, "" ) . is_err( ) ) ;
491
495
}
492
496
}
Original file line number Diff line number Diff line change @@ -35,6 +35,37 @@ Caused by:
35
35
. run ( ) ;
36
36
}
37
37
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
+
38
69
#[ cargo_test]
39
70
fn same_name ( ) {
40
71
// Feature with the same name as a dependency.
You can’t perform that action at this time.
0 commit comments