diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2025-03-09 06:55:03 +0000 |
---|---|---|
committer | Sven-Hendrik Haase <svenstaro@gmail.com> | 2025-03-09 06:55:03 +0000 |
commit | 3351805fffadcb9747f772ca9ea05e0d6d13619c (patch) | |
tree | d7c666d625d709354fcf03c31deaaf69d7e90fdb /src/main.rs | |
parent | Fix lints on Windows (diff) | |
download | miniserve-3351805fffadcb9747f772ca9ea05e0d6d13619c.tar.gz miniserve-3351805fffadcb9747f772ca9ea05e0d6d13619c.zip |
Fix dir size calculation for percent-encoded paths with spaces
Diffstat (limited to '')
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index adda3f7..a7166ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ use dav_server::{ }; use fast_qr::QRBuilder; use log::{error, info, warn}; +use percent_encoding::percent_decode_str; use serde::Deserialize; mod archive; @@ -455,10 +456,14 @@ async fn api( config: web::Data<MiniserveConfig>, ) -> Result<impl Responder, RuntimeError> { match command.into_inner() { - ApiCommand::DirSize(dir) => { - // Convert the relative dir to an absolute path on the system - let sanitized_path = - file_utils::sanitize_path(&dir, true).expect("Expected a path to directory"); + ApiCommand::DirSize(path) => { + // The dir argument might be percent-encoded so let's decode it just in case. + let decoded_path = percent_decode_str(&path) + .decode_utf8() + .map_err(|e| RuntimeError::ParseError(path.clone(), e.to_string()))?; + // Convert the relative dir to an absolute path on the system. + let sanitized_path = file_utils::sanitize_path(&*decoded_path, true) + .expect("Expected a path to directory"); let full_path = config .path .canonicalize() |