Skip to content

Commit

Permalink
Errors on empty taxonomies term
Browse files Browse the repository at this point in the history
Closes #2085
  • Loading branch information
Keats committed Feb 16, 2023
1 parent f363ea1 commit 60d8425
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/content/src/front_matter/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 60d8425

Please sign in to comment.