mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-28 21:41:35 +00:00
parser: reject closing delims that look like an op
This commit is contained in:
parent
d5710c9d4b
commit
e4c5ca3f6b
@ -360,6 +360,26 @@ impl<'a> RawSyntax<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for end in [syntax.block_end, syntax.expr_end, syntax.comment_end] {
|
||||||
|
for prefix in ["<<", ">>", "&&", "..", "||"] {
|
||||||
|
if end.starts_with(prefix) {
|
||||||
|
let msg = if end == prefix {
|
||||||
|
format!("a closing delimiter must not start with an operator: {end:?}")
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"a closing delimiter must not start an with operator: \
|
||||||
|
{end:?} starts with {prefix:?}",
|
||||||
|
)
|
||||||
|
};
|
||||||
|
return Err(CompileError::new_with_span(
|
||||||
|
msg,
|
||||||
|
file_info.copied(),
|
||||||
|
config_span,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(syntax)
|
Ok(syntax)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
testing/issue-128-2.toml
Normal file
4
testing/issue-128-2.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[[syntax]]
|
||||||
|
name = "mwe"
|
||||||
|
expr_start = "<<<"
|
||||||
|
expr_end = ">>>"
|
4
testing/issue-128.toml
Normal file
4
testing/issue-128.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[[syntax]]
|
||||||
|
name = "mwe"
|
||||||
|
expr_start = "<<"
|
||||||
|
expr_end = ">>"
|
17
testing/tests/ui/terminator-operator.rs
Normal file
17
testing/tests/ui/terminator-operator.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
use rinja::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "<<a>> and <<b>>", config = "issue-128.toml", syntax = "mwe", ext="")]
|
||||||
|
struct HelloTemplate {
|
||||||
|
a: u32,
|
||||||
|
b: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(source = "<<a>> and <<b>>", config = "issue-128-2.toml", syntax = "mwe", ext="")]
|
||||||
|
struct HelloTemplate2 {
|
||||||
|
a: u32,
|
||||||
|
b: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
13
testing/tests/ui/terminator-operator.stderr
Normal file
13
testing/tests/ui/terminator-operator.stderr
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
error: a closing delimiter must not start with an operator: ">>"
|
||||||
|
--> testing/issue-128.toml
|
||||||
|
--> tests/ui/terminator-operator.rs:4:49
|
||||||
|
|
|
||||||
|
4 | #[template(source = "<<a>> and <<b>>", config = "issue-128.toml", syntax = "mwe", ext="")]
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: a closing delimiter must not start an with operator: ">>>" starts with ">>"
|
||||||
|
--> testing/issue-128-2.toml
|
||||||
|
--> tests/ui/terminator-operator.rs:11:49
|
||||||
|
|
|
||||||
|
11 | #[template(source = "<<a>> and <<b>>", config = "issue-128-2.toml", syntax = "mwe", ext="")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
Loading…
x
Reference in New Issue
Block a user