mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-28 13:30:59 +00:00
Allow idents to start with _
This commit is contained in:
parent
f86feddbb4
commit
f39a846598
@ -633,7 +633,12 @@ fn path_or_identifier(i: &str) -> ParseResult<'_, PathOrIdentifier<'_>> {
|
||||
path.extend(rest);
|
||||
Ok((i, PathOrIdentifier::Path(path)))
|
||||
}
|
||||
(None, name, []) if name.chars().next().map_or(true, char::is_lowercase) => {
|
||||
(None, name, [])
|
||||
if name
|
||||
.chars()
|
||||
.next()
|
||||
.map_or(true, |c| c == '_' || c.is_lowercase()) =>
|
||||
{
|
||||
Ok((i, PathOrIdentifier::Identifier(name)))
|
||||
}
|
||||
(None, start, tail) => {
|
||||
|
@ -21,3 +21,13 @@ fn let_macro() {
|
||||
let template = A { y: false };
|
||||
assert_eq!(template.render().unwrap(), "blob")
|
||||
}
|
||||
|
||||
// Ensures that variables name can start with `_`.
|
||||
#[test]
|
||||
fn underscore() {
|
||||
#[derive(Template)]
|
||||
#[template(source = r#"{% let _x = 7 %}{{ _x }}"#, ext = "html")]
|
||||
struct X;
|
||||
|
||||
assert_eq!(X.render().unwrap(), "7")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user