From 64274f4de5c364d107034cfd2c007c146b5b6800 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 4 Jan 2025 17:04:35 +0000 Subject: [PATCH] Fix splitting logic --- backend/sync_server/src/utils.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/sync_server/src/utils.rs b/backend/sync_server/src/utils.rs index dad4534..8718944 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/_"); + } }