@@ -19,6 +19,7 @@ use crate::models::{
1919
2020use crate :: middleware:: log_request:: RequestLogExt ;
2121use crate :: models:: token:: EndpointScope ;
22+ use crate :: models:: version:: validate_license_expr;
2223use crate :: rate_limiter:: LimitedAction ;
2324use crate :: schema:: * ;
2425use crate :: sql:: canon_crate_name;
@@ -115,7 +116,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
115116 let package = tarball_info. manifest . package . unwrap ( ) ;
116117
117118 let description = package. description . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
118- let license = package. license . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
119+ let mut license = package. license . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
119120 let license_file = package. license_file . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
120121
121122 // Make sure required fields are provided
@@ -136,6 +137,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
136137 return Err ( cargo_err ( & message) ) ;
137138 }
138139
140+ if let Some ( ref license) = license {
141+ validate_license_expr ( license) ?;
142+ } else if license_file. is_some ( ) {
143+ // If no license is given, but a license file is given, flag this
144+ // crate as having a nonstandard license. Note that we don't
145+ // actually do anything else with license_file currently.
146+ license = Some ( String :: from ( "non-standard" ) ) ;
147+ }
148+
139149 // Create a transaction on the database, if there are no errors,
140150 // commit the transactions to record a new or updated crate.
141151 conn. transaction ( |conn| {
0 commit comments