mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 00:44:26 +02:00
Decode special characters when handling static files
This commit is contained in:
23
src/fs.rs
23
src/fs.rs
@ -761,7 +761,7 @@ impl<S: 'static, C: StaticFileConfig> StaticFiles<S, C> {
|
|||||||
&self,
|
&self,
|
||||||
req: &HttpRequest<S>,
|
req: &HttpRequest<S>,
|
||||||
) -> Result<AsyncResult<HttpResponse>, Error> {
|
) -> Result<AsyncResult<HttpResponse>, 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('/'))?;
|
let relpath = PathBuf::from_param(tail.trim_left_matches('/'))?;
|
||||||
|
|
||||||
// full filepath
|
// full filepath
|
||||||
@ -1303,6 +1303,27 @@ mod tests {
|
|||||||
assert_eq!(bytes, data);
|
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)]
|
#[derive(Default)]
|
||||||
pub struct OnlyMethodHeadConfig;
|
pub struct OnlyMethodHeadConfig;
|
||||||
impl StaticFileConfig for OnlyMethodHeadConfig {
|
impl StaticFileConfig for OnlyMethodHeadConfig {
|
||||||
|
1
tests/test space.binary
Normal file
1
tests/test space.binary
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>TǑɂV<EFBFBD>2<EFBFBD>vI<EFBFBD><EFBFBD><EFBFBD>\<5C>R˙<52><CB99><EFBFBD>e<EFBFBD><04>vD<76>:藽<>RV<03>Yp<59><70>;<3B><>G<><47>p!2<7F>C<EFBFBD>.<2E><0C><><EFBFBD><EFBFBD>pA!<21>ߦ<EFBFBD>x j+Uc<55><63><EFBFBD>X<13>c%<17>;<3B>"y<10><>AI
|
Reference in New Issue
Block a user