Skip to content

Commit

Permalink
fix(serve): content can be served from output_path
Browse files Browse the repository at this point in the history
This fixes a bug introduced in #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`.
  • Loading branch information
stanistan committed Jan 2, 2024
1 parent e5f3026 commit df19f5e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit df19f5e

Please sign in to comment.