diff options
author | Lukas Stabe <lukas@stabe.de> | 2020-08-21 00:21:13 +0000 |
---|---|---|
committer | Lukas Stabe <lukas@stabe.de> | 2020-08-21 00:21:13 +0000 |
commit | d8196e76621e673b40ab2ec6fe8527c1e0b7bc3e (patch) | |
tree | b9a5580fe28baf01b1bd8957f8801e51f7f7e563 /src | |
parent | Merge pull request #361 from svenstaro/dependabot/cargo/chrono-0.4.15 (diff) | |
download | miniserve-d8196e76621e673b40ab2ec6fe8527c1e0b7bc3e.tar.gz miniserve-d8196e76621e673b40ab2ec6fe8527c1e0b7bc3e.zip |
url-decode path in title and heading
Diffstat (limited to 'src')
-rw-r--r-- | src/listing.rs | 15 | ||||
-rw-r--r-- | src/renderer.rs | 13 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/listing.rs b/src/listing.rs index 388153f..6970c36 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -5,7 +5,7 @@ use actix_web::web::Query; use actix_web::{HttpRequest, HttpResponse, Result}; use bytesize::ByteSize; use htmlescape::encode_minimal as escape_html_entity; -use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; +use percent_encoding::{utf8_percent_encode, percent_decode_str, AsciiSet, CONTROLS}; use qrcodegen::{QrCode, QrCodeEcc}; use serde::Deserialize; use std::io; @@ -165,9 +165,17 @@ pub fn directory_listing( let base = Path::new(serve_path); let random_route = format!("/{}", random_route.unwrap_or_default()); let is_root = base.parent().is_none() || Path::new(&req.path()) == Path::new(&random_route); - let current_dir = match base.strip_prefix(random_route) { + let encoded_dir = match base.strip_prefix(random_route) { Ok(c_d) => Path::new("/").join(c_d), Err(_) => base.to_path_buf(), + }.display().to_string(); + let display_dir = { + let decoded = percent_decode_str(&encoded_dir).decode_utf8_lossy(); + if is_root { + decoded.to_string() + } else { + format!("{}/", decoded) + } }; let query_params = extract_query_parameters(req); @@ -350,7 +358,8 @@ pub fn directory_listing( show_qrcode, file_upload, &upload_route, - ¤t_dir.display().to_string(), + &encoded_dir, + &display_dir, tar_enabled, zip_enabled, ) diff --git a/src/renderer.rs b/src/renderer.rs index 7270e8f..a01b0a1 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -22,13 +22,14 @@ pub fn page( show_qrcode: bool, file_upload: bool, upload_route: &str, - current_dir: &str, + encoded_dir: &str, + display_dir: &str, tar_enabled: bool, zip_enabled: bool, ) -> Markup { let upload_action = build_upload_action( upload_route, - current_dir, + encoded_dir, sort_method, sort_order, color_scheme, @@ -38,7 +39,7 @@ pub fn page( html! { (DOCTYPE) html { - (page_header(serve_path, color_scheme, file_upload, false)) + (page_header(display_dir, color_scheme, file_upload, false)) body#drop-container { @if file_upload { div.drag-form { @@ -50,7 +51,7 @@ pub fn page( (color_scheme_selector(sort_method, sort_order, color_scheme, default_color_scheme, serve_path, show_qrcode)) div.container { span#top { } - h1.title { "Index of " (serve_path) } + h1.title { "Index of " (display_dir) } div.toolbar { @if tar_enabled || zip_enabled { div.download { @@ -107,13 +108,13 @@ pub fn page( /// Build the action of the upload form fn build_upload_action( upload_route: &str, - current_dir: &str, + encoded_dir: &str, sort_method: Option<SortingMethod>, sort_order: Option<SortingOrder>, color_scheme: ColorScheme, default_color_scheme: ColorScheme, ) -> String { - let mut upload_action = format!("{}?path={}", upload_route, current_dir); + let mut upload_action = format!("{}?path={}", upload_route, encoded_dir); if let Some(sorting_method) = sort_method { upload_action = format!("{}&sort={}", upload_action, &sorting_method); } |