| 1 | pub fn validate_username(u: &str) -> bool { |
| 2 | let bytes = u.as_bytes(); |
| 3 | if u.len() < 2 || u.len() > 32 { return false; } |
| 4 | if !(bytes[0].is_ascii_lowercase() || bytes[0].is_ascii_digit()) { return false; } |
| 5 | u.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_' || c == '-') |
| 6 | } |
| 7 | |
| 8 | pub fn validate_repo_name(r: &str) -> bool { |
| 9 | if r.len() < 2 || r.len() > 64 { return false; } |
| 10 | if r.ends_with(".git") { return false; } |
| 11 | let bytes = r.as_bytes(); |
| 12 | if !(bytes[0].is_ascii_lowercase() || bytes[0].is_ascii_digit()) { return false; } |
| 13 | r.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '.' || c == '_' || c == '-') |
| 14 | } |
| 15 | |
| 16 | const RESERVED_PATHS: &[&str] = &[ |
| 17 | "api", "scripts", "admin", "static", "assets", |
| 18 | "login", "signup", "settings", "new", "explore", |
| 19 | "install.sh", "favicon.ico", "robots.txt", |
| 20 | ]; |
| 21 | |
| 22 | pub fn is_reserved_path(s: &str) -> bool { |
| 23 | RESERVED_PATHS.contains(&s) |
| 24 | } |