1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 18:44:35 +01:00

Merge branch 'master' of github.com:actix/actix-web

This commit is contained in:
Nikolay Kim 2018-11-08 16:15:45 -08:00
commit aed3933ae8
3 changed files with 21 additions and 10 deletions

View File

@ -64,11 +64,11 @@ cell = ["actix-net/cell"]
actix = "^0.7.5" actix = "^0.7.5"
actix-net = "0.2.0" actix-net = "0.2.0"
askama_escape = "0.1.0"
base64 = "0.10" base64 = "0.10"
bitflags = "1.0" bitflags = "1.0"
failure = "^0.1.2" failure = "^0.1.2"
h2 = "0.1" h2 = "0.1"
htmlescape = "0.3"
http = "^0.1.8" http = "^0.1.8"
httparse = "1.3" httparse = "1.3"
log = "0.4" log = "0.4"

View File

@ -11,10 +11,10 @@ use std::{cmp, io};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use askama_escape::{escape as escape_html_entity};
use bytes::Bytes; use bytes::Bytes;
use futures::{Async, Future, Poll, Stream}; use futures::{Async, Future, Poll, Stream};
use futures_cpupool::{CpuFuture, CpuPool}; use futures_cpupool::{CpuFuture, CpuPool};
use htmlescape::encode_minimal as escape_html_entity;
use mime; use mime;
use mime_guess::{get_mime_type, guess_mime_type}; use mime_guess::{get_mime_type, guess_mime_type};
use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
@ -562,6 +562,20 @@ impl Directory {
} }
} }
// show file url as relative to static path
macro_rules! encode_file_url {
($path:ident) => {
utf8_percent_encode(&$path.to_string_lossy(), DEFAULT_ENCODE_SET)
};
}
// " -- &quot; & -- &amp; ' -- &#x27; < -- &lt; > -- &gt; / -- &#x2f;
macro_rules! encode_file_name {
($entry:ident) => {
escape_html_entity(&$entry.file_name().to_string_lossy())
};
}
fn directory_listing<S>( fn directory_listing<S>(
dir: &Directory, dir: &Directory,
req: &HttpRequest<S>, req: &HttpRequest<S>,
@ -577,11 +591,6 @@ fn directory_listing<S>(
Ok(p) => base.join(p), Ok(p) => base.join(p),
Err(_) => continue, Err(_) => continue,
}; };
// show file url as relative to static path
let file_url = utf8_percent_encode(&p.to_string_lossy(), DEFAULT_ENCODE_SET)
.to_string();
// " -- &quot; & -- &amp; ' -- &#x27; < -- &lt; > -- &gt;
let file_name = escape_html_entity(&entry.file_name().to_string_lossy());
// if file is a directory, add '/' to the end of the name // if file is a directory, add '/' to the end of the name
if let Ok(metadata) = entry.metadata() { if let Ok(metadata) = entry.metadata() {
@ -589,13 +598,15 @@ fn directory_listing<S>(
let _ = write!( let _ = write!(
body, body,
"<li><a href=\"{}\">{}/</a></li>", "<li><a href=\"{}\">{}/</a></li>",
file_url, file_name encode_file_url!(p),
encode_file_name!(entry),
); );
} else { } else {
let _ = write!( let _ = write!(
body, body,
"<li><a href=\"{}\">{}</a></li>", "<li><a href=\"{}\">{}</a></li>",
file_url, file_name encode_file_url!(p),
encode_file_name!(entry),
); );
} }
} else { } else {

View File

@ -100,9 +100,9 @@ extern crate failure;
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate futures; extern crate futures;
extern crate askama_escape;
extern crate cookie; extern crate cookie;
extern crate futures_cpupool; extern crate futures_cpupool;
extern crate htmlescape;
extern crate http as modhttp; extern crate http as modhttp;
extern crate httparse; extern crate httparse;
extern crate language_tags; extern crate language_tags;