Fix splitting logic

This commit is contained in:
Andras Schmelczer 2025-01-04 17:04:35 +00:00
parent 388b7bfabb
commit 64274f4de5
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -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::<Vec<_>>()
.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/_");
}
}