From 3351805fffadcb9747f772ca9ea05e0d6d13619c Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 9 Mar 2025 07:55:03 +0100 Subject: Fix dir size calculation for percent-encoded paths with spaces --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main.rs') 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, ) -> Result { 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() -- cgit v1.2.3