fix: escape path-prefix/url-prefix different
This commit is contained in:
parent
ce154d9ebc
commit
b0cc901416
3 changed files with 11 additions and 11 deletions
|
@ -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<PrivateKey> {
|
|||
}
|
||||
Ok(PrivateKey(keys[0].to_owned()))
|
||||
}
|
||||
|
||||
pub fn encode_uri(v: &str) -> String {
|
||||
let parts: Vec<_> = v.split('/').map(urlencoding::encode).collect();
|
||||
parts.join("/")
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;
|
|||
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]
|
||||
|
|
|
@ -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 {
|
|||
<D:status>HTTP/1.1 200 OK</D:status>
|
||||
</D:propstat>
|
||||
</D:response>"#,
|
||||
prefix,
|
||||
escape_str_pcdata(prefix),
|
||||
escape_str_pcdata(&self.name),
|
||||
escape_str_pcdata(&self.base_name),
|
||||
mtime
|
||||
|
@ -840,7 +840,7 @@ impl PathItem {
|
|||
<D:status>HTTP/1.1 200 OK</D:status>
|
||||
</D:propstat>
|
||||
</D:response>"#,
|
||||
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<ContentRange>
|
|||
}
|
||||
|
||||
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<String> {
|
|||
}
|
||||
vec![address.to_owned()]
|
||||
}
|
||||
|
||||
fn encode_uri(v: &str) -> String {
|
||||
let parts: Vec<_> = v.split('/').map(urlencoding::encode).collect();
|
||||
parts.join("/")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue