From 67b4eb84181a79dd4d2f3a88d5aa33c3fd051478 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 24 Jan 2023 20:37:43 +0100 Subject: [PATCH] Errors on empty taxonomies term Closes #2085 --- components/content/src/front_matter/page.rs | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/content/src/front_matter/page.rs b/components/content/src/front_matter/page.rs index 9768045769..31e5401481 100644 --- a/components/content/src/front_matter/page.rs +++ b/components/content/src/front_matter/page.rs @@ -103,6 +103,14 @@ impl PageFrontMatter { f.date_to_datetime(); + for (_, terms) in &f.taxonomies { + for term in terms { + if term.trim().is_empty() { + bail!("A taxonomy term cannot be an empty string"); + } + } + } + if let Some(ref date) = f.date { if f.datetime.is_none() { bail!("`date` could not be parsed: {}.", date); @@ -474,4 +482,24 @@ taxonomies: assert_eq!(res2.taxonomies["categories"], vec!["Dev"]); assert_eq!(res2.taxonomies["tags"], vec!["Rust", "JavaScript"]); } + + #[test_case(&RawFrontMatter::Toml(r#" +title = "Hello World" + +[taxonomies] +tags = [""] +"#); "toml")] + #[test_case(&RawFrontMatter::Yaml(r#" +title: Hello World + +taxonomies: + tags: + - +"#); "yaml")] + fn errors_on_empty_taxonomy_term(content: &RawFrontMatter) { + // https://github.com/getzola/zola/issues/2085 + let res = PageFrontMatter::parse(content); + println!("{:?}", res); + assert!(res.is_err()); + } }