mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 22:41:13 +00:00
Remove restriction preventing to have |
surrounded by whistespace characters
This commit is contained in:
parent
41425e15aa
commit
d7bc44a87d
@ -899,20 +899,10 @@ fn filter<'a>(
|
||||
i: &'a str,
|
||||
level: &mut Level,
|
||||
) -> ParseResult<'a, (&'a str, Option<Vec<WithSpan<'a, Expr<'a>>>>)> {
|
||||
let (j, _) = skip_ws0.parse_next(i)?;
|
||||
let had_spaces = i.len() != j.len();
|
||||
let (j, _) = ('|', not('|')).parse_next(j)?;
|
||||
let (j, _) = (ws('|'), not('|')).parse_next(i)?;
|
||||
|
||||
if !had_spaces {
|
||||
*level = level.nest(i)?.1;
|
||||
cut_err((ws(identifier), opt(|i| Expr::arguments(i, *level, false)))).parse_next(j)
|
||||
} else {
|
||||
Err(winnow::error::ErrMode::Cut(ErrorContext::new(
|
||||
"the filter operator `|` must not be preceded by any whitespace characters\n\
|
||||
the binary OR operator is called `bitor` in rinja",
|
||||
i,
|
||||
)))
|
||||
}
|
||||
*level = level.nest(i)?.1;
|
||||
cut_err((ws(identifier), opt(|i| Expr::arguments(i, *level, false)))).parse_next(j)
|
||||
}
|
||||
|
||||
/// Returns the common parts of two paths.
|
||||
|
@ -436,3 +436,17 @@ fn test_filesizeformat() {
|
||||
|
||||
assert_eq!(S { s: Some(12) }.render().unwrap(), "12 B");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_whitespace_around_filter_operator() {
|
||||
#[derive(Template)]
|
||||
#[template(
|
||||
source = r#"{{ 12 |safe }}
|
||||
{{ 8| safe }}
|
||||
{{ 4 | safe }}"#,
|
||||
ext = "html"
|
||||
)]
|
||||
struct S;
|
||||
|
||||
assert_eq!(S.render().unwrap(), "12\n8\n4");
|
||||
}
|
||||
|
@ -14,13 +14,6 @@ struct BitAndIso646 {
|
||||
b: u32,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{ a | b }}")]
|
||||
struct BitOr {
|
||||
a: u32,
|
||||
b: u32,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{ a bitor b }}")]
|
||||
struct BitOrIso646 {
|
||||
@ -36,7 +29,7 @@ struct Xor {
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{ a xor b }}")]
|
||||
#[template(ext = "txt", source = "{{ a xor b }} {{ c }}")]
|
||||
struct XorIso646 {
|
||||
a: u32,
|
||||
b: u32,
|
||||
|
@ -6,19 +6,18 @@ error: the binary AND operator is called `bitand` in rinja
|
||||
4 | #[template(ext = "txt", source = "{{ a & b }}")]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: the filter operator `|` must not be preceded by any whitespace characters
|
||||
the binary OR operator is called `bitor` in rinja
|
||||
--> <source attribute>:1:4
|
||||
" | b }}"
|
||||
--> tests/ui/iso646.rs:18:34
|
||||
|
|
||||
18 | #[template(ext = "txt", source = "{{ a | b }}")]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: the binary XOR operator is called `xor` in rinja
|
||||
--> <source attribute>:1:6
|
||||
" b }}"
|
||||
--> tests/ui/iso646.rs:32:34
|
||||
--> tests/ui/iso646.rs:25:34
|
||||
|
|
||||
32 | #[template(ext = "txt", source = "{{ a ^ b }}")]
|
||||
25 | #[template(ext = "txt", source = "{{ a ^ b }}")]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0609]: no field `c` on type `&XorIso646`
|
||||
--> tests/ui/iso646.rs:31:10
|
||||
|
|
||||
31 | #[derive(Template)]
|
||||
| ^^^^^^^^ unknown field
|
||||
|
|
||||
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
@ -1,28 +0,0 @@
|
||||
use rinja::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{a|lower}}")]
|
||||
struct Lower1<'a> {
|
||||
a: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{a |lower}}")]
|
||||
struct Lower2<'a> {
|
||||
a: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{a| lower}}")]
|
||||
struct Lower3<'a> {
|
||||
a: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "txt", source = "{{a | lower}}")]
|
||||
struct Lower4<'a> {
|
||||
a: &'a str,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
error: the filter operator `|` must not be preceded by any whitespace characters
|
||||
the binary OR operator is called `bitor` in rinja
|
||||
--> <source attribute>:1:3
|
||||
" |lower}}"
|
||||
--> tests/ui/space-pipe.rs:10:34
|
||||
|
|
||||
10 | #[template(ext = "txt", source = "{{a |lower}}")]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: the filter operator `|` must not be preceded by any whitespace characters
|
||||
the binary OR operator is called `bitor` in rinja
|
||||
--> <source attribute>:1:3
|
||||
" | lower}}"
|
||||
--> tests/ui/space-pipe.rs:22:34
|
||||
|
|
||||
22 | #[template(ext = "txt", source = "{{a | lower}}")]
|
||||
| ^^^^^^^^^^^^^^^
|
Loading…
x
Reference in New Issue
Block a user