Fix full template render choking on empty fields

This commit is contained in:
Damien Elmes 2023-06-27 16:30:41 +10:00
parent dc56a2ca7d
commit 5506f9bf2d
2 changed files with 14 additions and 10 deletions

View file

@ -225,7 +225,7 @@ mod test {
// should work even if unknown filters are encountered
let mut tmpl = nt.templates[0].clone();
tmpl.config.q_format = "{{some_filter:Front}}".into();
tmpl.config.q_format = "{{some_filter:Front}}{{another_filter:}}".into();
let out = col.render_uncommitted_card(&mut note, &nt.templates[0], 0, false, false)?;
assert_eq!(&out.question(), "front");

View file

@ -446,7 +446,8 @@ fn render_into(
}
}
Replacement { key, filters } => {
if context.partial_for_python && key.is_empty() && !filters.is_empty() {
if key.is_empty() && !filters.is_empty() {
if context.partial_for_python {
// if a filter is provided, we accept an empty field name to
// mean 'pass an empty string to the filter, and it will add
// its own text'
@ -455,6 +456,9 @@ fn render_into(
current_text: "".to_string(),
filters: filters.clone(),
});
} else {
// nothing to do
}
} else {
// apply built in filters if field exists
let (text, remaining_filters) = match context.fields.get(key.as_str()) {