askama icon indicating copy to clipboard operation
askama copied to clipboard

Ignore whitespace between method name and argument list

Open cipriancraciun opened this issue 4 years ago • 4 comments

The following simple template fails:

{{ model.test ("test-from-model") }}

Just by removing the whitespace between the test and (... solves the issue.

cipriancraciun avatar May 15 '20 08:05 cipriancraciun

Yeah, I guess. I am unlikely to work on this anytime soon, but if you want to take a crack at implementing I could provide you with some pointers.

djc avatar May 15 '20 08:05 djc

OK, could you give me the needed pointers?

(Although I agree it's low priority, given that my coding styles aren't inline with the 99%; however this weekend perhaps I'll take a look.)

cipriancraciun avatar May 15 '20 08:05 cipriancraciun

You'll need to update https://github.com/djc/askama/blob/master/askama_shared/src/parser.rs#L307 (and probably also expr_path_call() a few lines down) to eat the extra whitespace. Please also add test cases for any changes you make (could be either unit tests in the parser or full integration tests).

djc avatar May 15 '20 08:05 djc

OK, trying to solve this issue, I've came across the following ambiguity in the language regarding filter application and bitwise-or.

Say I have the following two templates a|b and a | b:

  • the first one a|b is interpreted as applying the b filter to a, when used fails complaining that the filter b does not exist;
  • the second one a | b is interpreted as a bitwise operator between a and b;

For example in the NestedFilterTemplate x|mytrim|safe if rewritten as x | mytrim | safe fails by saying that safe is not a member of the template.

cipriancraciun avatar May 25 '20 10:05 cipriancraciun