Sanitize accents out of folder name

This commit is contained in:
Arnaud_Cayrol 2026-02-04 20:53:58 +01:00
parent 49f3dd6386
commit 6b8963a81a
2 changed files with 10 additions and 1 deletions

View file

@ -50,6 +50,7 @@ tokio-util = "0.7"
futures-util = "0.3"
async-trait = "0.1"
dotenvy = "0.15"
unicode-normalization = "0.1"
[dev-dependencies]
tokio-test = "0.4"

View file

@ -1,5 +1,7 @@
//! Shared utility functions.
use unicode_normalization::{char::is_combining_mark, UnicodeNormalization};
/// Create a safe snake_case folder name from person name or ID.
///
/// This sanitizes user input to create safe filesystem paths by:
@ -15,8 +17,14 @@
pub fn sanitize_folder_name(name: Option<&str>, id: &str) -> String {
let base = name.filter(|n| !n.is_empty()).unwrap_or(id);
// Remove accents by decomposing to NFD and filtering combining marks
let without_accents: String = base
.nfd()
.filter(|c| !is_combining_mark(*c))
.collect();
// Convert to lowercase and replace unsafe characters with underscores
let sanitized: String = base
let sanitized: String = without_accents
.to_lowercase()
.chars()
.map(|c| {