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
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
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:
parent
301aa53830
commit
5286618648
|
|
@ -1,6 +1,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use md5;
|
use md5;
|
||||||
|
use std::borrow::Cow;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
///Max file name size supported by the file system
|
///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())
|
.map_or("", |filename| filename.to_str().unwrap())
|
||||||
.to_string();
|
.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('/') {
|
if url_path_and_query.ends_with('/') {
|
||||||
filename = "index.html".to_string();
|
filename = "index.html".to_string();
|
||||||
parent = url_path_and_query.trim_end_matches('/').to_string();
|
parent = url_path_and_query.trim_end_matches('/').to_string();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue