diff --git a/src/fs.rs b/src/fs.rs index 05024da85..47bd81a78 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -761,7 +761,7 @@ impl StaticFiles { &self, req: &HttpRequest, ) -> Result, Error> { - let tail: String = req.match_info().query("tail")?; + let tail: String = req.match_info().get_decoded("tail").unwrap_or_else(|| "".to_string()); let relpath = PathBuf::from_param(tail.trim_left_matches('/'))?; // full filepath @@ -1303,6 +1303,27 @@ mod tests { assert_eq!(bytes, data); } + #[test] + fn test_static_files_with_spaces() { + let mut srv = test::TestServer::with_factory(|| { + App::new().handler( + "/", + StaticFiles::new(".").unwrap().index_file("Cargo.toml"), + ) + }); + let request = srv + .get() + .uri(srv.url("/tests/test%20space.binary")) + .finish() + .unwrap(); + let response = srv.execute(request.send()).unwrap(); + assert_eq!(response.status(), StatusCode::OK); + + let bytes = srv.execute(response.body()).unwrap(); + let data = Bytes::from(fs::read("tests/test space.binary").unwrap()); + assert_eq!(bytes, data); + } + #[derive(Default)] pub struct OnlyMethodHeadConfig; impl StaticFileConfig for OnlyMethodHeadConfig { diff --git a/tests/test space.binary b/tests/test space.binary new file mode 100644 index 000000000..ef8ff0245 --- /dev/null +++ b/tests/test space.binary @@ -0,0 +1 @@ +TǑɂV2vI\R˙evD:藽RVYp;Gp!2C. pA !ߦx j+UcXc%;"yAI \ No newline at end of file