From 0ec21d198aa3532a70b5bbb579029b1b0f7bb492 Mon Sep 17 00:00:00 2001 From: Lilith Ashley Nyx Arson Date: Thu, 2 Jan 2025 18:26:30 +0100 Subject: [PATCH] url encoding changes --- Cargo.lock | 8 +++++++- Cargo.toml | 2 +- src/directory_listing.rs | 13 +++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f885dc..cb9aaf3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 335355e..060ff63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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' diff --git a/src/directory_listing.rs b/src/directory_listing.rs index f57defe..08119b6 100644 --- a/src/directory_listing.rs +++ b/src/directory_listing.rs @@ -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; // " -- " & -- & ' -- ' < -- < > -- > / -- / @@ -18,7 +17,7 @@ pub fn directory_listing( dir: &Directory, req: &HttpRequest, ) -> Result { - 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::(), - ) + .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::(), - ) + .join(&*urlencoding::encode(&p.to_str().unwrap())) .to_string_lossy() .into_owned(), Err(_) => continue,