Skip to content

Commit 67b4eb8

Browse files
committed
Errors on empty taxonomies term
Closes getzola#2085
1 parent a4d3adf commit 67b4eb8

File tree

1 file changed

+28
-0
lines changed
  • components/content/src/front_matter

1 file changed

+28
-0
lines changed

components/content/src/front_matter/page.rs

+28
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ impl PageFrontMatter {
103103

104104
f.date_to_datetime();
105105

106+
for (_, terms) in &f.taxonomies {
107+
for term in terms {
108+
if term.trim().is_empty() {
109+
bail!("A taxonomy term cannot be an empty string");
110+
}
111+
}
112+
}
113+
106114
if let Some(ref date) = f.date {
107115
if f.datetime.is_none() {
108116
bail!("`date` could not be parsed: {}.", date);
@@ -474,4 +482,24 @@ taxonomies:
474482
assert_eq!(res2.taxonomies["categories"], vec!["Dev"]);
475483
assert_eq!(res2.taxonomies["tags"], vec!["Rust", "JavaScript"]);
476484
}
485+
486+
#[test_case(&RawFrontMatter::Toml(r#"
487+
title = "Hello World"
488+
489+
[taxonomies]
490+
tags = [""]
491+
"#); "toml")]
492+
#[test_case(&RawFrontMatter::Yaml(r#"
493+
title: Hello World
494+
495+
taxonomies:
496+
tags:
497+
-
498+
"#); "yaml")]
499+
fn errors_on_empty_taxonomy_term(content: &RawFrontMatter) {
500+
// https://github.com/getzola/zola/issues/2085
501+
let res = PageFrontMatter::parse(content);
502+
println!("{:?}", res);
503+
assert!(res.is_err());
504+
}
477505
}

0 commit comments

Comments
 (0)