1
Fork 0

Validate crate name in CLI option --extern

This commit is contained in:
León Orell Valerian Liehr 2023-08-18 13:23:53 +02:00
parent f0727758d1
commit 8d81d5a909
No known key found for this signature in database
GPG key ID: D17A07215F68E713
15 changed files with 60 additions and 17 deletions

View file

@ -158,3 +158,12 @@ pub fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
if !result.is_empty() { Some((result, excluded_cargo_defaults)) } else { None }
}
pub(crate) fn is_ascii_ident(string: &str) -> bool {
let mut chars = string.chars();
if let Some(start) = chars.next() && (start.is_ascii_alphabetic() || start == '_') {
chars.all(|char| char.is_ascii_alphanumeric() || char == '_')
} else {
false
}
}