diff --git a/backend/sync_server/src/utils.rs b/backend/sync_server/src/utils.rs index dad45349..8718944c 100644 --- a/backend/sync_server/src/utils.rs +++ b/backend/sync_server/src/utils.rs @@ -8,5 +8,26 @@ pub fn sanitize_path(path: &str) -> String { replacement: "", }; - sanitize_filename::sanitize_with_options(path, options) + path.split('/') + .map(|part| { + let proposal = sanitize_filename::sanitize_with_options(part, options.clone()); + if !part.is_empty() && proposal.is_empty() { + "_".to_owned() + } else { + proposal + } + }) + .collect::>() + .join("/") +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_sanitize_path() { + assert_eq!(sanitize_path("/my/path/what?"), "/my/path/what"); + assert_eq!(sanitize_path("/my/path/\\\\:?"), "/my/path/_"); + } }