Fix .. behaviour
This commit is contained in:
parent
61a2c4912f
commit
ef99f445e0
|
@ -68,8 +68,7 @@ fn handle_connection(mut stream: TcpStream, root_dir: String) {
|
|||
|
||||
let get = format!( "{} {} {}\r\n {}\r\n", host, _path, _post_len, _post);
|
||||
let _get_bytes = get.as_bytes();
|
||||
|
||||
let status_line = if Path::new(&format!("{}{}", root_dir, _path).to_string()).exists() {
|
||||
let status_line = if Path::new(&format!("{}{}", root_dir, _path).to_string()).exists() && !_path.contains(".."){
|
||||
"2 text/gemini"
|
||||
} else {
|
||||
"4 Not found"
|
||||
|
@ -84,6 +83,9 @@ fn handle_connection(mut stream: TcpStream, root_dir: String) {
|
|||
} else {
|
||||
exists = Path::new(&format!("{}{}/index.gmi", root_dir, _path).to_string()).exists();
|
||||
if exists {
|
||||
if _path.contains("..") {
|
||||
return;
|
||||
}
|
||||
_contents = fs::read_to_string(format!("{}{}index.gmi", root_dir, _path)).unwrap_or_else(|error| {
|
||||
if error.kind() == ErrorKind::NotFound {
|
||||
panic!("NotFound error!");
|
||||
|
@ -92,6 +94,9 @@ fn handle_connection(mut stream: TcpStream, root_dir: String) {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
if _path.contains("..") {
|
||||
return;
|
||||
}
|
||||
_contents = format!("=> ..\n");
|
||||
let path_to_folder = full_path.clone();
|
||||
let files = fs::read_dir(path_to_folder).unwrap();
|
||||
|
|
Loading…
Reference in New Issue