tera
tera copied to clipboard
Multiple brackets do not work sometimes
Hi,
In recent days while developing our internal project with the use of Tera, we've found (probably) a bug connected with expressions including multiple nested parentheses.
For example, the following template:
<p>{{ ( ( _somePrice.cash / _somePrice.period ) + ( _somePrice.cash / _somePrice.period ) ) }}</p>
parsed using the following rust code:
use tera::{Context, Tera};
use serde_json::{json, Value};
fn main() {
let json = json!({
"_somePrice": {
"cash": 10,
"period": 3
},
});
let context = Context::from_value(json).unwrap();
let result = Tera::one_off(include_str!("../trivial.txt"), &context, true);
println!("{:#?}", result);
}
returns an error:
Err(
Error {
kind: Msg(
"Failed to parse '__tera_one_off'",
),
source: Some(
Error {
kind: Msg(
" --> 1:31\n |\n1 | <p>{{ ( ( _somePrice.cash ) + ( _somePrice.cash ) ) }}</p>\n | ^---\n |\n = expected an integer, a float, `true` or `false`, an identifier (must start with a-z), a dotted identifier (identifiers separated by `.`), or a square bracketed identifier (identifiers separated by `.` or `[]`s)",
),
source: None,
},
),
},
)
(There is no line wrapping on GitHub code snippets, so keep in mind you've to scroll horizontally in order to read the entire error message)
With the following template, everything passes fine:
<p>{{ ( _somePrice.cash / _somePrice.period ) + ( _somePrice.cash / _somePrice.period ) }}</p>
Steps to reproduce:
- Clone
[email protected]:dsplce-co/tera-bracket-poc.git - Run
cargo run --example trivialorcargo run --example complex
Can somebody help with that? Above we've provided a minimal example but we had more real-life templates we wanted to use and it cannot be done 'cause of this issue.
The current version parser is pretty limited when it comes to parenthesis. Tera v2 will have a normal full support but no timeline whatsoever.