mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
Decode special characters when handling static files
This commit is contained in:
parent
55a2a59906
commit
4d45313f9d
23
src/fs.rs
23
src/fs.rs
@ -761,7 +761,7 @@ impl<S: 'static, C: StaticFileConfig> StaticFiles<S, C> {
|
||||
&self,
|
||||
req: &HttpRequest<S>,
|
||||
) -> 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('/'))?;
|
||||
|
||||
// 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 {
|
||||
|
1
tests/test space.binary
Normal file
1
tests/test space.binary
Normal file
@ -0,0 +1 @@
|
||||
ÂTÇ‘É‚Vù2þvI ª–\ÇRË™–ˆæeÞ<04>vDØ:è—½¬RVÖYpíÿ;ÍÏGñùp!2÷CŒ.–<0C>û®õpA!ûߦÙx j+Uc÷±©X”c%Û;ï"yìAI
|
Loading…
x
Reference in New Issue
Block a user