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:
Edouard Vanbelle
2026-05-08 00:11:02 +02:00
parent 405721c679
commit 6696ba3ae4
4 changed files with 49 additions and 34 deletions
+9 -8
View File
@@ -1,6 +1,6 @@
use uuid::Uuid;
use crate::domain::services::path_service::StoragePath;
use crate::domain::services::path_service::{StoragePath, validate_storage_name};
// Re-export entity errors from the centralized module
pub use super::entity_errors::{FolderError, FolderResult};
@@ -71,8 +71,8 @@ impl Folder {
owner_id: Option<Uuid>,
) -> FolderResult<Self> {
// Validate folder name
if name.is_empty() || name.contains('/') || name.contains('\\') {
return Err(FolderError::InvalidFolderName(name));
if let Err(reason) = validate_storage_name(&name) {
return Err(FolderError::InvalidFolderName(format!("{name}: {reason}")));
}
let now = std::time::SystemTime::now()
@@ -126,8 +126,8 @@ impl Folder {
modified_at: u64,
) -> FolderResult<Self> {
// Validate folder name
if name.is_empty() || name.contains('/') || name.contains('\\') {
return Err(FolderError::InvalidFolderName(name));
if let Err(reason) = validate_storage_name(&name) {
return Err(FolderError::InvalidFolderName(format!("{name}: {reason}")));
}
// Store the path string for serialization compatibility
@@ -208,9 +208,10 @@ impl Folder {
/// Creates a new version of the folder with updated name
pub fn with_name(&self, new_name: String) -> FolderResult<Self> {
// Validate folder name
if new_name.is_empty() || new_name.contains('/') || new_name.contains('\\') {
return Err(FolderError::InvalidFolderName(new_name));
if let Err(reason) = validate_storage_name(&new_name) {
return Err(FolderError::InvalidFolderName(format!(
"{new_name}: {reason}"
)));
}
// Update path based on the name