MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / validate_view_name

Function validate_view_name

atomic-cli/src/commands/view/new.rs:96–136  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

runMethod · 0.70
test_empty_nameFunction · 0.70
test_name_too_longFunction · 0.70

Calls 3

is_emptyMethod · 0.45
lenMethod · 0.45
containsMethod · 0.45

Tested by 2

test_empty_nameFunction · 0.56
test_name_too_longFunction · 0.56