From 0513940305ffd771d08d627a8e8c49cd58fabd5b Mon Sep 17 00:00:00 2001 From: "a.r" <887320+twwn@users.noreply.github.com> Date: Sat, 26 Oct 2024 11:58:52 +0200 Subject: [PATCH] template_filters: make {{type:}} forwards compatible (#3525) Make Anki treat {{type:unknown:field}} field replacements as {{type:field}} instead of {{field}}. The previous behavior was seriously inconvenient for several reasons, including: * Updated client aren't all released at the same time, causing an unavoidable mismatch period. Now it causes the least friction. * Devs couldn't readily test new in-dev variants without breaking/inconveniencing their own mobile experience. * Some users will have (potentially perpetually) outdated Anki clients and likely complain, wasting both dev & deck creator time. This way users always get to type and especially: The front side will always render as intended. --- rslib/src/template_filters.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/rslib/src/template_filters.rs b/rslib/src/template_filters.rs index 13d092134..f1aac788c 100644 --- a/rslib/src/template_filters.rs +++ b/rslib/src/template_filters.rs @@ -31,12 +31,12 @@ pub(crate) fn apply_filters<'a>( let mut text: Cow = text.into(); // type:cloze & type:nc are handled specially - let filters = if filters == ["cloze", "type"] { - &["type-cloze"] - } else if filters == ["nc", "type"] { - &["type-nc"] - } else { - filters + // other type: are passed as the default one + let filters = match filters { + ["cloze", "type"] => &["type-cloze"], + ["nc", "type"] => &["type-nc"], + [.., "type"] => &["type"], + _ => filters, }; for (idx, &filter_name) in filters.iter().enumerate() { @@ -259,6 +259,10 @@ field apply_filters("ignored", &["nc", "type"], "Text", &ctx), ("[[type:nc:Text]]".into(), vec![]) ); + assert_eq!( + apply_filters("ignored", &["some", "unknown", "type"], "Text", &ctx), + ("[[type:Text]]".into(), vec![]) + ); } #[test]