From ccad454922dfcbf3c2b68b35248cb00f81775123 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 7 Jan 2021 19:16:31 +0100 Subject: [PATCH] Percent decode paths on zola serve --- CHANGELOG.md | 1 + Cargo.lock | 1 + Cargo.toml | 1 + src/cmd/serve.rs | 7 ++++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b79d5c..35a1a451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ content - Remove `zola serve --watch-only`: since we build the HTML in memory and not on disk, it doesn't make sense anymore - Update clojure syntax - Prefer extra syntaxes to the default ones if we have a match for language +- Fix `zola serve` having issues with non-ascii paths ## 0.12.2 (2020-09-28) diff --git a/Cargo.lock b/Cargo.lock index 56b643a0..dd0ebdc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3263,6 +3263,7 @@ dependencies = [ "lazy_static", "notify", "open", + "percent-encoding", "relative-path", "serde_json", "site", diff --git a/Cargo.toml b/Cargo.toml index e52d36c3..5445f5c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ url = "2" # Below is for the serve cmd hyper = { version = "0.14.1", default-features = false, features = ["runtime", "server", "http2", "http1"] } tokio = { version = "1.0.1", default-features = false, features = ["rt", "fs"] } +percent-encoding = "2" notify = "4" ws = "0.9" ctrlc = "3" diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 459bf2fb..39ab47f9 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -72,8 +72,13 @@ const LIVE_RELOAD: &str = include_str!("livereload.js"); async fn handle_request(req: Request, mut root: PathBuf) -> Result> { let mut path = RelativePathBuf::new(); + // https://zola.discourse.group/t/percent-encoding-for-slugs/736 + let decoded = match percent_encoding::percent_decode_str(req.uri().path()).decode_utf8() { + Ok(d) => d, + Err(_) => return Ok(not_found()), + }; - for c in req.uri().path().split('/') { + for c in decoded.split('/') { path.push(c); }