Sanitize relative paths server-side

This commit is contained in:
Andras Schmelczer 2025-01-04 16:16:54 +00:00
parent 0943681702
commit 6d5b183a3c
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
6 changed files with 44 additions and 12 deletions

View file

@ -0,0 +1,12 @@
/// Sanitize the document's path to allow all clients to create the same path in
/// their filesystem. If we didn't do this server-side, client's would need to
/// deal with mapping invalid names to valid ones and then back.
pub fn sanitize_path(path: &str) -> String {
let options = sanitize_filename::Options {
truncate: true,
windows: true, // Windows is the lowest common denominator
replacement: "",
};
sanitize_filename::sanitize_with_options(path, options)
}