work around weird canonicalize() behaviour on windows

This commit is contained in:
Crispy 2024-03-25 14:45:38 +01:00
parent 702a1dc024
commit 7f37d4a775

View file

@ -113,10 +113,18 @@ fn handle_request(request: String, stream: &mut TcpStream) -> bool {
fn get_file(request: Request) -> Option<(Content, bool)> {
const MAX_SIZE: usize = 1024 * 1024 * 8;
let path = PathBuf::from(format!("./{}", &request.path))
let current_dir = env::current_dir().unwrap();
let path = current_dir
.join(request.path.strip_prefix('/')?)
.canonicalize()
.ok()?;
if path.strip_prefix(env::current_dir().unwrap()).is_err() {
if path
.strip_prefix(current_dir.canonicalize().unwrap())
.is_err()
{
println!("illegal path: {}", request.path);
return None;
}