fix(storage names): enure folder and file names are not using reserved chars
- create common function `validate_storage_name()` to check files & folder name - replace previous duplicate check with this one - better check on create_folder rename_folder (was only checking non empty) - use correct error class to ensure 400 on API (was 500) fix: #345 note: no unit test here, but plan e2e test for that next: improve UI to display error
This commit is contained in:
@@ -6,6 +6,26 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Validates a single file or folder name component.
|
||||
///
|
||||
/// Returns `Err` with a human-readable reason if the name is rejected.
|
||||
/// Callers should wrap the reason into their own error type.
|
||||
pub fn validate_storage_name(name: &str) -> Result<(), &'static str> {
|
||||
if name.is_empty() {
|
||||
return Err("name cannot be empty");
|
||||
}
|
||||
if name.contains('/') || name.contains('\\') {
|
||||
return Err("name must not contain '/' or '\\'");
|
||||
}
|
||||
if name.contains('\0') {
|
||||
return Err("name must not contain null bytes");
|
||||
}
|
||||
if name == "." || name == ".." {
|
||||
return Err("'.' and '..' are not valid names");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Represents a storage path in the domain (Value Object)
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct StoragePath {
|
||||
|
||||
Reference in New Issue
Block a user