work around weird canonicalize() behaviour on windows
This commit is contained in:
parent
702a1dc024
commit
7f37d4a775
1 changed files with 10 additions and 2 deletions
12
src/main.rs
12
src/main.rs
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue