@@ -67,6 +67,8 @@ pub const ALL_COLUMNS: AllColumns = (crates::id, crates::name,
67
67
crates:: readme, crates:: license, crates:: repository,
68
68
crates:: max_upload_size) ;
69
69
70
+ pub const MAX_NAME_LENGTH : usize = 64 ;
71
+
70
72
type CrateQuery < ' a > = crates:: BoxedQuery < ' a , Pg , <AllColumns as Expression >:: SqlType > ;
71
73
72
74
#[ derive( RustcEncodable , RustcDecodable ) ]
@@ -370,6 +372,13 @@ impl Crate {
370
372
}
371
373
372
374
pub fn valid_name ( name : & str ) -> bool {
375
+ let under_max_length = name. chars ( )
376
+ . take ( MAX_NAME_LENGTH + 1 )
377
+ . count ( ) <= MAX_NAME_LENGTH ;
378
+ Crate :: valid_ident ( name) && under_max_length
379
+ }
380
+
381
+ fn valid_ident ( name : & str ) -> bool {
373
382
if name. is_empty ( ) { return false }
374
383
name. chars ( ) . next ( ) . unwrap ( ) . is_alphabetic ( ) &&
375
384
name. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' || c == '-' ) &&
@@ -379,12 +388,12 @@ impl Crate {
379
388
pub fn valid_feature_name ( name : & str ) -> bool {
380
389
let mut parts = name. split ( '/' ) ;
381
390
match parts. next ( ) {
382
- Some ( part) if !Crate :: valid_name ( part) => return false ,
391
+ Some ( part) if !Crate :: valid_ident ( part) => return false ,
383
392
None => return false ,
384
393
_ => { }
385
394
}
386
395
match parts. next ( ) {
387
- Some ( part) if !Crate :: valid_name ( part) => return false ,
396
+ Some ( part) if !Crate :: valid_ident ( part) => return false ,
388
397
_ => { }
389
398
}
390
399
parts. next ( ) . is_none ( )
0 commit comments