From 93754f307f4e3ffc1e895ccb87d8ad61368d178c Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 4 Jan 2022 04:08:46 +0000 Subject: [PATCH] try path config from Data as well --- actix-files/src/directory.rs | 13 +++++++++++-- actix-router/src/url.rs | 1 + src/types/path.rs | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/actix-files/src/directory.rs b/actix-files/src/directory.rs index 80e0c98d..26225ea5 100644 --- a/actix-files/src/directory.rs +++ b/actix-files/src/directory.rs @@ -40,14 +40,23 @@ impl Directory { pub(crate) type DirectoryRenderer = dyn Fn(&Directory, &HttpRequest) -> Result; -// show file url as relative to static path +/// Returns percent encoded file URL path. macro_rules! encode_file_url { ($path:ident) => { utf8_percent_encode(&$path, CONTROLS) }; } -// " -- " & -- & ' -- ' < -- < > -- > / -- / +/// Returns HTML entity encoded formatter. +/// +/// ```plain +/// " => " +/// & => & +/// ' => ' +/// < => < +/// > => > +/// / => / +/// ``` macro_rules! encode_file_name { ($entry:ident) => { escape_html_entity(&$entry.file_name().to_string_lossy(), Html) diff --git a/actix-router/src/url.rs b/actix-router/src/url.rs index fee8eaaf..156c1e1c 100644 --- a/actix-router/src/url.rs +++ b/actix-router/src/url.rs @@ -340,6 +340,7 @@ mod tests { assert_eq!(q.requote(b"/a%25b%2Bc").unwrap(), "/a%b+c"); assert_eq!(q.requote(b"/a%2fb").unwrap(), "/a%2fb"); assert_eq!(q.requote(b"/a%2Fb").unwrap(), "/a%2Fb"); + assert_eq!(q.requote(b"/a%0Ab").unwrap(), "/a\nb"); } #[test] diff --git a/src/types/path.rs b/src/types/path.rs index 4b60d27c..4a694b76 100644 --- a/src/types/path.rs +++ b/src/types/path.rs @@ -9,6 +9,7 @@ use serde::de; use crate::{ dev::Payload, error::{Error, ErrorNotFound, PathError}, + web::Data, FromRequest, HttpRequest, }; @@ -102,6 +103,7 @@ where fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { let error_handler = req .app_data::() + .or_else(|| req.app_data::>().map(Data::get_ref)) .and_then(|c| c.err_handler.clone()); ready( @@ -113,6 +115,7 @@ where Request path: {:?}", req.path() ); + if let Some(error_handler) = error_handler { let e = PathError::Deserialize(err); (error_handler)(e, req)