Merge pull request #519 from Kijewski/4793932351602688

parser: fix `check_expr()` recursion
This commit is contained in:
Guillaume Gomez 2025-07-05 22:48:00 +02:00 committed by GitHub
commit 6b936f4c1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 56 additions and 8 deletions

View File

@ -110,9 +110,11 @@ fn check_expr<'a>(expr: &WithSpan<'a, Expr<'a>>, allowed: Allowed) -> ParseResul
}
Ok(())
}
Expr::As(elem, _) | Expr::Unary(_, elem) | Expr::Group(elem) => {
check_expr(elem, Allowed::default())
}
Expr::As(elem, _)
| Expr::Unary(_, elem)
| Expr::Group(elem)
| Expr::NamedArgument(_, elem)
| Expr::Try(elem) => check_expr(elem, Allowed::default()),
Expr::Call(v) => {
check_expr(
&v.path,
@ -126,17 +128,20 @@ fn check_expr<'a>(expr: &WithSpan<'a, Expr<'a>>, allowed: Allowed) -> ParseResul
}
Ok(())
}
Expr::Filter(filter) => {
for arg in &filter.arguments {
check_expr(arg, Allowed::default())?;
}
Ok(())
}
Expr::LetCond(cond) => check_expr(&cond.expr, Allowed::default()),
Expr::ArgumentPlaceholder => cut_error!("unreachable", expr.span),
Expr::BoolLit(_)
| Expr::NumLit(_, _)
| Expr::StrLit(_)
| Expr::CharLit(_)
| Expr::Filter(_)
| Expr::NamedArgument(_, _)
| Expr::RustMacro(_, _)
| Expr::Try(_)
| Expr::FilterSource
| Expr::LetCond(_) => Ok(()),
| Expr::FilterSource => Ok(()),
}
}

View File

@ -1592,3 +1592,45 @@ fn test_macro_call_nested_comments() {
)],
);
}
#[test]
fn test_try_reserved_raw_identifier() {
// Regression test for <https://issues.oss-fuzz.com/issues/429130577>.
let syntax = Syntax::default();
for id in ["crate", "super", "Self"] {
let msg = format!("`{id}` cannot be used as an identifier");
assert!(
Ast::from_str(&format!("{{{{ {id}? }}}}"), None, &syntax)
.unwrap_err()
.to_string()
.contains(&msg),
);
assert!(
Ast::from_str(&format!("{{{{ {id}|filter }}}}"), None, &syntax)
.unwrap_err()
.to_string()
.contains(&msg),
);
assert!(
Ast::from_str(
&format!("{{{{ var|filter(arg1, {id}, arg3) }}}}"),
None,
&syntax
)
.unwrap_err()
.to_string()
.contains(&msg),
);
assert!(
Ast::from_str(
&format!("{{{{ var|filter(arg1=arg1, arg2={id}, arg3=arg3) }}}}"),
None,
&syntax
)
.unwrap_err()
.to_string()
.contains(&msg),
);
}
}

View File

@ -0,0 +1 @@
˙˙˙{{crate?}} ˙d˙Ĺ