From b9c9b39d4c656c3e740ed6f1a7ecc130f8aea60d Mon Sep 17 00:00:00 2001 From: Gary Hai Date: Wed, 20 Jun 2018 21:17:11 +0800 Subject: [PATCH] Fix duplicate tail of StaticFiles with index_file. And fix the unit test cases by add request path. --- src/fs.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 639626c57..795928cb4 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -676,10 +676,6 @@ impl Handler for StaticFiles { // TODO: It'd be nice if there were a good usable URL manipulation // library let mut new_path: String = req.path().to_owned(); - for el in relpath.iter() { - new_path.push_str(&el.to_string_lossy()); - new_path.push('/'); - } if !new_path.ends_with('/') { new_path.push('/'); } @@ -1205,10 +1201,11 @@ mod tests { #[test] fn test_redirect_to_index() { let mut st = StaticFiles::new(".").index_file("index.html"); - let mut req = HttpRequest::default(); + let mut req = TestRequest::default().uri("/tests").finish(); req.match_info_mut().add_static("tail", "tests"); + let req2 = req.clone(); - let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap(); + let resp = st.handle(req).respond_to(&req2).unwrap(); let resp = resp.as_msg(); assert_eq!(resp.status(), StatusCode::FOUND); assert_eq!( @@ -1216,10 +1213,11 @@ mod tests { "/tests/index.html" ); - let mut req = HttpRequest::default(); + let mut req = TestRequest::default().uri("/tests/").finish(); req.match_info_mut().add_static("tail", "tests/"); + let req2 = req.clone(); - let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap(); + let resp = st.handle(req).respond_to(&req2).unwrap(); let resp = resp.as_msg(); assert_eq!(resp.status(), StatusCode::FOUND); assert_eq!( @@ -1231,10 +1229,11 @@ mod tests { #[test] fn test_redirect_to_index_nested() { let mut st = StaticFiles::new(".").index_file("mod.rs"); - let mut req = HttpRequest::default(); + let mut req = TestRequest::default().uri("/src/client").finish(); req.match_info_mut().add_static("tail", "src/client"); + let req2 = req.clone(); - let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap(); + let resp = st.handle(req).respond_to(&req2).unwrap(); let resp = resp.as_msg(); assert_eq!(resp.status(), StatusCode::FOUND); assert_eq!(