Skip to content

Commit

Permalink
parser: add missing level guard in if let
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Feb 1, 2025
1 parent 9b0ed3c commit 5ad19f3
Show file tree
Hide file tree
Showing 6 changed files with 9,747 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ group_imports = "StdExternalCrate"
imports_granularity = "Module"
newline_style = "Unix"
normalize_comments = true
overflow_delimited_expr = true
style_edition = "2024"
unstable_features = true
use_field_init_shorthand = true
style_edition = "2024"

ignore = [
"testing/tests/hello.rs",
Expand Down
1 change: 1 addition & 0 deletions rinja/.rustfmt.toml
1 change: 1 addition & 0 deletions rinja_parser/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl<'a> CondTest<'a> {
let mut expr = Expr::parse(i, s.level, false)?;
if let Expr::BinOp(_, _, ref mut right) = expr.inner {
if matches!(right.inner, Expr::Var("set" | "let")) {
let _level_guard = s.level.nest(i)?;
*i = right.span.as_suffix_of(start).unwrap();
let start_span = Span::from(*i);
let new_right = Self::parse_cond(i, s)?;
Expand Down
11 changes: 11 additions & 0 deletions rinja_parser/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,3 +1288,14 @@ fn test_generics_parsing() {
)
.unwrap();
}

#[test]
fn fuzzed_deeply_tested_if_let() {
let src = include_str!("../tests/fuzzed-deeply-tested-if-let.txt");
let syntax = Syntax::default();
let err = Ast::from_str(src, None, &syntax).unwrap_err();
assert_eq!(
err.to_string().lines().next(),
Some("your template code is too deeply nested, or the last expression is too complex"),
);
}
Loading

0 comments on commit 5ad19f3

Please sign in to comment.