From 0282c62a739f9c9a36635d23355857628c84eaf6 Mon Sep 17 00:00:00 2001 From: Stan Rozenraukh Date: Sun, 7 Jan 2024 14:37:33 -0500 Subject: [PATCH] fix(serve): content can be served from output_path (#2398) This fixes a bug introduced in https://github.com/getzola/zola/pull/2258 The issue arose when `output_path` was relative. The request being served would be canonicalized and this would be a string. So, for example, if you were serving content from `public` the code [right after](https://github.com/getzola/zola/blob/38199c125501e9ff0e700e96adaca72cc3f25d2b/src/cmd/serve.rs#L144-L147) the canonicalization checking if `root.starts_with(original_root)` would always return `false` since an absolute path, `/some/path/to/content` would never start with a string like `public`. --- src/cmd/serve.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 2f2f718e3e..dce008e1fa 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -461,9 +461,9 @@ pub fn serve( let ws_address = format!("{}:{}", interface, ws_port.unwrap()); let output_path = site.output_path.clone(); - // output path is going to need to be moved later on, so clone it for the - // http closure to avoid contention. - let static_root = output_path.clone(); + // static_root needs to be canonicalized because we do the same for the http server. + let static_root = std::fs::canonicalize(&output_path).unwrap(); + let broadcaster = { thread::spawn(move || { let addr = address.parse().unwrap();