Validate a view name. View names must: - Not be empty - Not exceed 255 characters - Not contain invalid characters (/, \, :, *, ?, ", <, >, |, space, null) - Not start or end with a dot - Not be "." or ".." # Arguments `name` - The view name to validate # Returns `Ok(())` if the name is valid, or an error describing why it's invalid.
(name: &str)
| 89 | /// |
| 90 | /// `Ok(())` if the name is valid, or an error describing why it's invalid. |
| 91 | fn validate_view_name(name: &str) -> Result<(), String> { |
| 92 | // Check for empty name |
| 93 | if name.is_empty() { |
| 94 | return Err("View name cannot be empty".to_string()); |
| 95 | } |
| 96 | |
| 97 | // Check length |
| 98 | if name.len() > MAX_VIEW_NAME_LENGTH { |
| 99 | return Err(format!( |
| 100 | "View name cannot exceed {} characters", |
| 101 | MAX_VIEW_NAME_LENGTH |
| 102 | )); |
| 103 | } |
| 104 | |
| 105 | // Check for invalid characters |
| 106 | for c in INVALID_CHARS { |
| 107 | if name.contains(*c) { |
| 108 | let char_desc = match c { |
| 109 | ' ' => "spaces".to_string(), |
| 110 | '\0' => "null characters".to_string(), |
| 111 | _ => format!("'{}'", c), |
| 112 | }; |
| 113 | return Err(format!("View name cannot contain {}", char_desc)); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // Check for reserved names |
| 118 | if name == "." || name == ".." { |
| 119 | return Err("View name cannot be '.' or '..'".to_string()); |
| 120 | } |
| 121 | |
| 122 | // Check for leading/trailing dots |
| 123 | if name.starts_with('.') { |
| 124 | return Err("View name cannot start with a dot".to_string()); |
| 125 | } |
| 126 | if name.ends_with('.') { |
| 127 | return Err("View name cannot end with a dot".to_string()); |
| 128 | } |
| 129 | |
| 130 | Ok(()) |
| 131 | } |
| 132 | |
| 133 | // New Command |
| 134 |