GithubHelp home page GithubHelp logo

Comments (4)

tkindy avatar tkindy commented on July 22, 2024

Just to check my understanding, I confirmed that Jinja handles this as I would expect.

jinja examples

from jinjava.

tkindy avatar tkindy commented on July 22, 2024

I believe I've found the bug, and it's even more basic than the examples so far in this issue. The template {{ -10 }} parses as -10 in Jinja and 10 in Jinjava.

The bug is coming from a feature of Jinjava (which, as expected, comes from Jinja) called whitespace control. In an expression or other block, you can add a dash at the beginning or end to control whether preceding or trailing whitespace on the line is trimmed. For example, the template {{- "foo" }} would trim all leading whitespace on the line ahead of foo.

The Jinja docs specify, "You must not add whitespace between the tag and the minus sign." However, the current Jinjava implementation allows whitespace in between the tag and the dash, so negative numbers at the start of expressions are having their minus sign interpreted as a whitespace control character by accident.

This is also the case in statements ({%), though I don't know of a valid statement off the top of my head that could start with a negative number.

I should be able to fix this relatively easily.

from jinjava.

tkindy avatar tkindy commented on July 22, 2024

I've managed to fix the whitespace control problem locally, but it's revealed another issue with operator precedence. Specifically, the unary minus should bind tighter than operators like is; that is, -1 is integer should evaluate the same as (-1) is integer. However, currently Jinjava evaluates this as -(1 is integer) which is obviously incorrect.

This is a tougher issue to untangle, but I did a fair amount of digging yesterday and hope to make some more progress today. I opened #893 to capture this issue.

from jinjava.

tkindy avatar tkindy commented on July 22, 2024

I had to revert #896 while we look into some templates that no longer parse successfully with these changes.

from jinjava.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.