File: stop-at-first-error-from-StrftimeItems.diff

package info (click to toggle)
rust-tera 1.20.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: makefile: 2
file content (20 lines) | stat: -rw-r--r-- 920 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Description: stop at first error from StrftimeItems
 Since chrono 0.4.41 StrftimeItems can return a never-ending iterator,
 which causes tera's tests to hang. I've filed a bug about this in chrono,
 but tera has no reason to go beyond the first error (it doesn't look at
 any of the error details) so lets stop there.
Author: Peter Michael Green <plugwash@debian.org>

--- rust-tera-1.20.0.orig/src/builtins/filters/common.rs
+++ rust-tera-1.20.0/src/builtins/filters/common.rs
@@ -74,9 +74,7 @@ pub fn date(value: &Value, args: &HashMa
         None => "%Y-%m-%d".to_string(),
     };
 
-    let items: Vec<Item> =
-        StrftimeItems::new(&format).filter(|item| matches!(item, Item::Error)).collect();
-    if !items.is_empty() {
+    if StrftimeItems::new(&format).filter(|item| matches!(item, Item::Error)).next().is_some() {
         return Err(Error::msg(format!("Invalid date format `{}`", format)));
     }