From 6fbe1b22ea9929ea6f652e515a7156c0d4db19d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Wed, 28 Aug 2019 19:43:42 +0200 Subject: [PATCH] update percent-encoding and htmlescape * percent-encoding 1.0 to 2.0 * actualy move from htmlescape to v_htmlescape code updated for some api changes too --- Cargo.toml | 4 ++-- src/web.rs | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b145f9..2826ef9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ env_logger = "*" log = "*" futures = "0.1" tar = "0.4" -percent-encoding = "1.0" -htmlescape = "0.3" +percent-encoding = "2.0" +v_htmlescape = "0.4" [profile.release] opt-level = 'z' diff --git a/src/web.rs b/src/web.rs index 4dc1c03..0139c48 100644 --- a/src/web.rs +++ b/src/web.rs @@ -2,8 +2,8 @@ use actix_web::{App, middleware, error, HttpServer, HttpRequest, HttpResponse, R use actix_web::dev::ServiceResponse; use actix_files as fs; use futures::Stream; -use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; -use htmlescape::encode_minimal as escape_html_entity; +use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; +use v_htmlescape::escape as escape_html_entity; use crate::channel; @@ -48,19 +48,18 @@ fn handle_directory<'a, 'b>( paths.sort_by_key(|entry| (!optimistic_is_dir(entry), entry.file_name())); - let dir_tar_path = String::from(req.path().trim_end_matches('/')) + ".tar"; - let tar_url = utf8_percent_encode(&dir_tar_path, DEFAULT_ENCODE_SET).to_string(); + let tar_url = req.path().trim_end_matches('/'); // this is already encoded let mut body = String::new(); - writeln!(body, "

Index of {}

", req.path()).unwrap(); - writeln!(body, r#"[.tar of whole directory]"#, tar_url).unwrap(); + writeln!(body, "

Index of {}

", req.path()).unwrap(); // FIXME: decode from url, escape for html + writeln!(body, r#"[.tar of whole directory]"#, tar_url).unwrap(); writeln!(body, "").unwrap(); writeln!(body, "").unwrap(); for entry in paths { let meta = entry.metadata()?; - let file_url = utf8_percent_encode(&entry.file_name().to_string_lossy(), DEFAULT_ENCODE_SET).to_string(); - let file_name = escape_html_entity(&entry.file_name().to_string_lossy()); + let file_url = utf8_percent_encode(&entry.file_name().to_string_lossy(), NON_ALPHANUMERIC).to_string(); + let file_name = escape_html_entity(&entry.file_name().to_string_lossy()).to_string(); let size = meta.len(); write!(body, "").unwrap();
📁 ../Size