fix: limit folder names length to avoid crashes

This commit is contained in:
FlashOnFire_ 2025-06-12 22:36:14 +02:00
parent f7d5ec7a5a
commit 2baac5a093
No known key found for this signature in database

View file

@ -1,6 +1,7 @@
use std::path::Path;
use md5;
use std::borrow::Cow;
use url::Url;
///Max file name size supported by the file system
@ -25,6 +26,19 @@ pub fn to_path(url: &Url, with_fragment: bool) -> String {
.map_or("", |filename| filename.to_str().unwrap())
.to_string();
// Ensure the folder names are not too long
parent = parent
.split('/')
.map(|str| {
if str.len() > FILE_NAME_MAX_LENGTH {
Cow::Owned(format!("{:x}", md5::compute(str)))
} else {
Cow::Borrowed(str)
}
})
.collect::<Vec<Cow<str>>>()
.join("/");
if url_path_and_query.ends_with('/') {
filename = "index.html".to_string();
parent = url_path_and_query.trim_end_matches('/').to_string();