fix: limit folder names length to avoid crashes
Some checks failed
Clippy / clippy (push) Has been cancelled
code-coverage / Rust project (push) Has been cancelled
Build and test / lint (push) Has been cancelled
Build and test / Build ${{ matrix.target }}-${{ matrix.rust }} on ${{ matrix.os }} (ubuntu-latest, 1.70.0, riscv64gc-unknown-linux-gnu) (push) Has been cancelled
Build and test / Build ${{ matrix.target }}-${{ matrix.rust }} on ${{ matrix.os }} (ubuntu-latest, 1.70.0, x86_64-unknown-linux-gnu) (push) Has been cancelled
Build and test / Build ${{ matrix.target }}-${{ matrix.rust }} on ${{ matrix.os }} (ubuntu-latest, stable, aarch64-unknown-linux-gnu) (push) Has been cancelled
Build and test / Build ${{ matrix.target }}-${{ matrix.rust }} on ${{ matrix.os }} (ubuntu-latest, stable, riscv64gc-unknown-linux-gnu) (push) Has been cancelled
Build and test / Build ${{ matrix.target }}-${{ matrix.rust }} on ${{ matrix.os }} (ubuntu-latest, stable, x86_64-unknown-linux-gnu) (push) Has been cancelled
Build and test / Tests ${{ matrix.target }} on ${{ matrix.os }} (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Build and test / Build ${{ matrix.target }}-${{ matrix.rust }} on ${{ matrix.os }} (ubuntu-latest, 1.70.0, aarch64-unknown-linux-gnu) (push) Has been cancelled

This commit is contained in:
FlashOnFire_ 2025-06-12 22:36:14 +02:00 committed by Esteban Blanc
parent 301aa53830
commit 5286618648

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();