From c2979760b5d9e7525ea7bfeb17936b760a3afa0c Mon Sep 17 00:00:00 2001 From: Gary Hai Date: Tue, 26 Jun 2018 00:37:24 +0800 Subject: [PATCH] Fix duplicate tail of StaticFiles with index_file. (#344) --- src/fs.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index a8f66dede..817e4d425 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -653,10 +653,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('/'); } @@ -1017,7 +1013,8 @@ 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("tail", "tests"); let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap(); @@ -1028,7 +1025,7 @@ mod tests { "/tests/index.html" ); - let mut req = HttpRequest::default(); + let mut req = TestRequest::default().uri("/tests/").finish(); req.match_info_mut().add("tail", "tests/"); let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap(); @@ -1043,7 +1040,7 @@ mod tests { #[test] fn test_redirect_to_index_nested() { let mut st = StaticFiles::new(".").index_file("Cargo.toml"); - let mut req = HttpRequest::default(); + let mut req = TestRequest::default().uri("/tools/wsload").finish(); req.match_info_mut().add("tail", "tools/wsload"); let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();