aboutsummaryrefslogtreecommitdiffstats
path: root/askama_parser/src/node.rs
diff options
context:
space:
mode:
authorLibravatar Guillaume Gomez <guillaume1.gomez@gmail.com>2024-01-22 15:35:59 +0100
committerLibravatar Guillaume Gomez <guillaume1.gomez@gmail.com>2024-01-22 17:13:01 +0100
commit29687db996307463ac2f4de01f67704e909dd1fe (patch)
treea76ef90413652b5e0205e82cfaa57fc89f36cf6f /askama_parser/src/node.rs
parenteb4c4ec9152f68a381fc3c2eee6e7ed14a2c73c8 (diff)
downloadaskama-29687db996307463ac2f4de01f67704e909dd1fe.tar.gz
askama-29687db996307463ac2f4de01f67704e909dd1fe.tar.bz2
askama-29687db996307463ac2f4de01f67704e909dd1fe.zip
Improve error when whitespace control is used on `extends`
Diffstat (limited to 'askama_parser/src/node.rs')
-rw-r--r--askama_parser/src/node.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs
index 3f5198c..16c5382 100644
--- a/askama_parser/src/node.rs
+++ b/askama_parser/src/node.rs
@@ -928,8 +928,22 @@ pub struct Extends<'a> {
impl<'a> Extends<'a> {
fn parse(i: &'a str) -> ParseResult<'a, Self> {
- let (i, path) = preceded(ws(keyword("extends")), cut(ws(str_lit)))(i)?;
- Ok((i, Self { path }))
+ let start = i;
+
+ let (i, (pws, _, (path, nws))) = tuple((
+ opt(Whitespace::parse),
+ ws(keyword("extends")),
+ cut(pair(ws(str_lit), opt(Whitespace::parse))),
+ ))(i)?;
+ match (pws, nws) {
+ (None, None) => Ok((i, Self { path })),
+ (_, _) => Err(nom::Err::Failure(ErrorContext {
+ input: start,
+ message: Some(Cow::Borrowed(
+ "whitespace control is not allowed on `extends`",
+ )),
+ })),
+ }
}
}