mirror of https://github.com/fafhrd91/actix-web
fix tests
This commit is contained in:
parent
892ee563b3
commit
d7b79c1f38
|
@ -85,8 +85,7 @@ impl FromRequest for PathBufWrap {
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
type Future = Ready<Result<Self, Self::Error>>;
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
// preferred over `req.path()` for safe percent decoding
|
ready(req.match_info().unprocessed().parse())
|
||||||
ready(req.match_info().as_str().parse())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,16 +120,16 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// `req.match_info().as_str()` preferred over `req.path()` for safe percent decoding
|
let path_on_disk = match PathBufWrap::parse_path(
|
||||||
|
req.match_info().unprocessed(),
|
||||||
let real_path =
|
this.hidden_files,
|
||||||
match PathBufWrap::parse_path(req.match_info().as_str(), this.hidden_files) {
|
) {
|
||||||
Ok(item) => item,
|
Ok(item) => item,
|
||||||
Err(err) => return Ok(req.error_response(err)),
|
Err(err) => return Ok(req.error_response(err)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(filter) = &this.path_filter {
|
if let Some(filter) = &this.path_filter {
|
||||||
if !filter(real_path.as_ref(), req.head()) {
|
if !filter(path_on_disk.as_ref(), req.head()) {
|
||||||
if let Some(ref default) = this.default {
|
if let Some(ref default) = this.default {
|
||||||
return default.call(req).await;
|
return default.call(req).await;
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,7 +139,7 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// full file path
|
// full file path
|
||||||
let path = this.directory.join(&real_path);
|
let path = this.directory.join(&path_on_disk);
|
||||||
if let Err(err) = path.canonicalize() {
|
if let Err(err) = path.canonicalize() {
|
||||||
return this.handle_err(err, req).await;
|
return this.handle_err(err, req).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ impl<T: ResourcePath> Path<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unprocessed(&self) -> &str {
|
pub fn unprocessed(&self) -> &str {
|
||||||
profile_method!(unprocessed);
|
profile_method!(unprocessed);
|
||||||
|
// clamp skip to path length
|
||||||
let skip = (self.skip as usize).min(self.as_str().len());
|
let skip = (self.skip as usize).min(self.as_str().len());
|
||||||
&self.path.path()[skip..]
|
&self.path.path()[skip..]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue