Skip to content

Commit

Permalink
filter: add check against large input
Browse files Browse the repository at this point in the history
  • Loading branch information
manunio authored and djc committed Jun 21, 2024
1 parent 2d7ecdf commit 382b5f6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion askama/src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl<S: fmt::Display> fmt::Display for TruncateFilter<S> {
#[inline]
pub fn indent(s: impl ToString, width: usize) -> Result<impl fmt::Display, Infallible> {
fn indent(s: String, width: usize) -> Result<String, Infallible> {
if width >= MAX_LEN {
if width >= MAX_LEN || s.len() >= MAX_LEN {
return Ok(s);
}
let mut indented = String::new();
Expand Down Expand Up @@ -834,4 +834,10 @@ mod tests {
assert_eq!(&title("fOO").unwrap(), "Foo");
assert_eq!(&title("fOo BaR").unwrap(), "Foo Bar");
}

#[test]
fn fuzzed_indent_filter() {
let s = "hello\nfoo\nbar".to_string().repeat(1024);
assert_eq!(indent(s.clone(), 4).unwrap().to_string(), s);
}
}

0 comments on commit 382b5f6

Please sign in to comment.