mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
parser: understand arbitrarily mixed up end nodes
This commit is contained in:
parent
e0a7d4df55
commit
5efd31310f
@ -1058,7 +1058,7 @@ fn end_node<'a, 'g: 'a>(
|
|||||||
let (i, actual) = ws(identifier)(start)?;
|
let (i, actual) = ws(identifier)(start)?;
|
||||||
if actual == expected {
|
if actual == expected {
|
||||||
Ok((i, actual))
|
Ok((i, actual))
|
||||||
} else if actual == "end" {
|
} else if actual.starts_with("end") {
|
||||||
Err(nom::Err::Failure(ErrorContext::new(
|
Err(nom::Err::Failure(ErrorContext::new(
|
||||||
format!("expected `{expected}` to terminate `{node}` node, found `{actual}`"),
|
format!("expected `{expected}` to terminate `{node}` node, found `{actual}`"),
|
||||||
start,
|
start,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: failed to parse template source
|
error: expected `endfor` to terminate `for` node, found `endfo`
|
||||||
--> <source attribute>:1:26
|
--> <source attribute>:1:26
|
||||||
"endfo%}\n1234567890123456789012345678901234567890"
|
"endfo%}\n1234567890123456789012345678901234567890"
|
||||||
--> tests/ui/typo_in_keyword.rs:5:14
|
--> tests/ui/typo_in_keyword.rs:5:14
|
||||||
|
@ -24,4 +24,8 @@ struct Block;
|
|||||||
#[template(source = "{% if true %}{% end %}", ext = "txt")]
|
#[template(source = "{% if true %}{% end %}", ext = "txt")]
|
||||||
struct If;
|
struct If;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "{% if true %}{% endfor %}", ext = "txt")]
|
||||||
|
struct IfFor;
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -45,3 +45,11 @@ error: expected `endif` to terminate `if` node, found `end`
|
|||||||
|
|
|
|
||||||
24 | #[template(source = "{% if true %}{% end %}", ext = "txt")]
|
24 | #[template(source = "{% if true %}{% end %}", ext = "txt")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: expected `endif` to terminate `if` node, found `endfor`
|
||||||
|
--> <source attribute>:1:15
|
||||||
|
" endfor %}"
|
||||||
|
--> tests/ui/wrong-end.rs:28:21
|
||||||
|
|
|
||||||
|
28 | #[template(source = "{% if true %}{% endfor %}", ext = "txt")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Loading…
x
Reference in New Issue
Block a user