url encoding changes

This commit is contained in:
Lilith Ashley Nyx Arson 🔥 2025-01-02 18:26:30 +01:00
parent df4c292ddb
commit 0ec21d198a
Signed by: lilith
SSH key fingerprint: SHA256:LAjgsAMyT3LO2JVtr6fQ4N3RTYoRRlIm5wAKsbDife4
3 changed files with 11 additions and 12 deletions

8
Cargo.lock generated
View file

@ -801,7 +801,7 @@ dependencies = [
"futures",
"log",
"percent-encoding",
"url",
"urlencoding",
"v_htmlescape",
]
@ -1587,6 +1587,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
name = "utf16_iter"
version = "1.0.5"

View file

@ -18,7 +18,7 @@ futures = "0.3.24"
percent-encoding = "2.2"
v_htmlescape = "0.15"
bytesize = "1.3.0"
url = "2.5.4"
urlencoding = "2.1.3"
[profile.release]
opt-level = 'z'

View file

@ -4,7 +4,6 @@ use actix_web::{HttpRequest, HttpResponse};
use bytesize::ByteSize;
use std::fmt::Write;
use std::path::Path;
use url::form_urlencoded;
use v_htmlescape::escape as escape_html_entity;
// " -- &quot; & -- &amp; ' -- &#x27; < -- &lt; > -- &gt; / -- &#x2f;
@ -18,7 +17,7 @@ pub fn directory_listing(
dir: &Directory,
req: &HttpRequest,
) -> Result<ServiceResponse, std::io::Error> {
let index_of = req.path().trim_end_matches('/');
let index_of = urlencoding::decode(req.path().trim_end_matches('/')).unwrap();
let mut body = String::new();
let base = Path::new(req.path());
@ -38,17 +37,11 @@ pub fn directory_listing(
for entry in paths {
let p: String = match entry.path().strip_prefix(&dir.path) {
Ok(p) if cfg!(windows) => base
.join(
form_urlencoded::byte_serialize(p.as_os_str().as_encoded_bytes())
.collect::<String>(),
)
.join(&*urlencoding::encode(p.to_str().unwrap()))
.to_string_lossy()
.replace('\\', "/"),
Ok(p) => base
.join(
form_urlencoded::byte_serialize(p.as_os_str().as_encoded_bytes())
.collect::<String>(),
)
.join(&*urlencoding::encode(&p.to_str().unwrap()))
.to_string_lossy()
.into_owned(),
Err(_) => continue,