Merge pull request #838 from AleoHQ/fix-package-name-check

Fix package name checks
This commit is contained in:
Collin Chin 2021-04-08 12:59:44 -07:00 committed by GitHub
commit 8b254b6b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,10 +68,16 @@ impl Package {
return false;
}
// Check that the first character is not a number.
if previous.is_numeric() {
tracing::error!("Project names cannot begin with a number");
return false;
}
// Iterate and check that the package name is valid.
for current in package_name.chars() {
// Check that the package name is lowercase.
if !current.is_ascii_lowercase() && current != '-' {
if current.is_ascii_uppercase() && current != '-' {
tracing::error!("Project names must be all lowercase");
return false;
}
@ -267,6 +273,8 @@ mod tests {
assert!(Package::is_package_name_valid("foo"));
assert!(Package::is_package_name_valid("foo-bar"));
assert!(Package::is_package_name_valid("foo-bar-baz"));
assert!(Package::is_package_name_valid("foo1"));
assert!(Package::is_package_name_valid("foo-1"));
assert!(!Package::is_package_name_valid(""));
assert!(!Package::is_package_name_valid("-"));
@ -279,5 +287,6 @@ mod tests {
assert!(!Package::is_package_name_valid("foo*bar"));
assert!(!Package::is_package_name_valid("foo,bar"));
assert!(!Package::is_package_name_valid("foo_bar"));
assert!(!Package::is_package_name_valid("1-foo"));
}
}