Fix field check for cloze conditional (#1975)

This commit is contained in:
RumovZ 2022-07-20 12:26:26 +02:00 committed by GitHub
parent 5f9fa51026
commit b9fd6688d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -502,9 +502,7 @@ impl<'a> RenderContext<'a> {
fn evaluate_conditional(&self, key: &str, negated: bool) -> TemplateResult<bool> {
if self.nonempty_fields.contains(key) {
Ok(true ^ negated)
} else if self.fields.contains_key(key)
|| (key.starts_with('c') && key[1..].parse::<u32>().is_ok())
{
} else if self.fields.contains_key(key) || is_cloze_conditional(key) {
Ok(false ^ negated)
} else {
let prefix = if negated { "^" } else { "#" };
@ -828,7 +826,7 @@ fn find_field_references<'a>(
}
ParsedNode::Conditional { key, children }
| ParsedNode::NegatedConditional { key, children } => {
if with_conditionals {
if with_conditionals && !is_cloze_conditional(key) {
fields.insert(key);
}
find_field_references(children, fields, cloze_only, with_conditionals);
@ -837,6 +835,11 @@ fn find_field_references<'a>(
}
}
fn is_cloze_conditional(key: &str) -> bool {
key.strip_prefix('c')
.map_or(false, |s| s.parse::<u32>().is_ok())
}
// Tests
//---------------------------------------