diff --git a/src/args.rs b/src/args.rs index c9c4e77..55e70e8 100644 --- a/src/args.rs +++ b/src/args.rs @@ -143,7 +143,7 @@ impl Args { let uri_prefix = if path_prefix.is_empty() { "/".to_owned() } else { - format!("/{}/", encode_uri(&path_prefix)) + format!("/{}/", &path_prefix) }; let cors = matches.is_present("cors"); let auth = match matches.value_of("auth") { @@ -237,8 +237,3 @@ pub fn load_private_key(filename: &str) -> BoxResult { } Ok(PrivateKey(keys[0].to_owned())) } - -pub fn encode_uri(v: &str) -> String { - let parts: Vec<_> = v.split('/').map(urlencoding::encode).collect(); - parts.join("/") -} diff --git a/src/main.rs b/src/main.rs index 176d7e6..3258e44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ pub type BoxResult = Result>; use std::env; use std::io::Write; -use crate::args::{encode_uri, matches, Args}; +use crate::args::{matches, Args}; use crate::server::serve; #[tokio::main] diff --git a/src/server.rs b/src/server.rs index 5bda54c..28dfd92 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,5 @@ use crate::auth::{generate_www_auth, valid_digest}; -use crate::{encode_uri, Args, BoxResult}; +use crate::{Args, BoxResult}; use xml::escape::escape_str_pcdata; use async_walkdir::WalkDir; @@ -822,7 +822,7 @@ impl PathItem { HTTP/1.1 200 OK "#, - prefix, + escape_str_pcdata(prefix), escape_str_pcdata(&self.name), escape_str_pcdata(&self.base_name), mtime @@ -840,7 +840,7 @@ impl PathItem { HTTP/1.1 200 OK "#, - prefix, + escape_str_pcdata(prefix), escape_str_pcdata(&self.name), escape_str_pcdata(&self.base_name), self.size.unwrap_or_default(), @@ -975,7 +975,7 @@ fn to_content_range(range: &Range, complete_length: u64) -> Option } fn print_listening(address: &str, port: u16, prefix: &str, tls: bool) { - let prefix = prefix.trim_end_matches('/'); + let prefix = encode_uri(prefix.trim_end_matches('/')); let addrs = retrieve_listening_addrs(address); let protocol = if tls { "https" } else { "http" }; if addrs.len() == 1 { @@ -1006,3 +1006,8 @@ fn retrieve_listening_addrs(address: &str) -> Vec { } vec![address.to_owned()] } + +fn encode_uri(v: &str) -> String { + let parts: Vec<_> = v.split('/').map(urlencoding::encode).collect(); + parts.join("/") +}