mirror of
https://github.com/actix/actix-web.git
synced 2024-12-23 00:26:34 +00:00
Fix StaticFiles does not support percent encoded paths #177
This commit is contained in:
parent
c0976bfa17
commit
22c776f46e
2 changed files with 21 additions and 1 deletions
|
@ -1,6 +1,11 @@
|
|||
# Changes
|
||||
|
||||
|
||||
## 0.5.2 (2018-04-xx)
|
||||
|
||||
* Fix StaticFiles does not support percent encoded paths #177
|
||||
|
||||
|
||||
## 0.5.1 (2018-04-12)
|
||||
|
||||
* Client connector provides stats, `ClientConnector::stats()`
|
||||
|
|
17
src/fs.rs
17
src/fs.rs
|
@ -15,6 +15,7 @@ use bytes::{Bytes, BytesMut, BufMut};
|
|||
use futures::{Async, Poll, Future, Stream};
|
||||
use futures_cpupool::{CpuPool, CpuFuture};
|
||||
use mime_guess::get_mime_type;
|
||||
use percent_encoding::percent_decode;
|
||||
|
||||
use header;
|
||||
use error::Error;
|
||||
|
@ -484,7 +485,10 @@ impl<S: 'static> Handler<S> for StaticFiles<S> {
|
|||
if !self.accessible {
|
||||
Ok(self.default.handle(req))
|
||||
} else {
|
||||
let relpath = match req.match_info().get("tail").map(PathBuf::from_param) {
|
||||
let relpath = match req.match_info().get("tail").map(
|
||||
|tail| percent_decode(tail.as_bytes()).decode_utf8().unwrap())
|
||||
.map(|tail| PathBuf::from_param(tail.as_ref()))
|
||||
{
|
||||
Some(Ok(path)) => path,
|
||||
_ => return Ok(self.default.handle(req))
|
||||
};
|
||||
|
@ -671,4 +675,15 @@ mod tests {
|
|||
let loc = response.headers().get(header::LOCATION).unwrap().to_str().unwrap();
|
||||
assert_eq!(loc, "/test/Cargo.toml");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn integration_percent_encoded() {
|
||||
let mut srv = test::TestServer::with_factory(
|
||||
|| App::new()
|
||||
.handler("test", StaticFiles::new(".").index_file("Cargo.toml")));
|
||||
|
||||
let request = srv.get().uri(srv.url("/test/%43argo.toml")).finish().unwrap();
|
||||
let response = srv.execute(request.send()).unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue