mirror of
https://github.com/Skallwar/suckit.git
synced 2026-09-10 07:16:19 -04:00
fix: limit folder names length to avoid crashes
This commit is contained in:
parent
f7d5ec7a5a
commit
2baac5a093
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue