mirror of
https://github.com/uutils/shadow.git
synced 2026-06-10 16:14:57 -07:00
validate.rs: remove unreachable!()
This commit is contained in:
@@ -31,10 +31,6 @@ const MAX_USERNAME_LEN: usize = 32;
|
||||
///
|
||||
/// Returns `ShadowError::Validation` if the username violates any rule.
|
||||
pub fn validate_username(name: &str) -> Result<(), ShadowError> {
|
||||
if name.is_empty() {
|
||||
return Err(ShadowError::Validation("username must not be empty".into()));
|
||||
}
|
||||
|
||||
if name.len() > MAX_USERNAME_LEN {
|
||||
return Err(ShadowError::Validation(
|
||||
format!("username '{name}' exceeds maximum length of {MAX_USERNAME_LEN} characters")
|
||||
@@ -45,7 +41,7 @@ pub fn validate_username(name: &str) -> Result<(), ShadowError> {
|
||||
let mut chars = name.chars();
|
||||
// Name is guaranteed non-empty by the check above.
|
||||
let Some(first) = chars.next() else {
|
||||
unreachable!("empty name already rejected");
|
||||
return Err(ShadowError::Validation("username must not be empty".into()));
|
||||
};
|
||||
|
||||
if !first.is_ascii_lowercase() && first != '_' {
|
||||
|
||||
Reference in New Issue
Block a user