New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strict_variables evaluating both operands of the and operator #651
Comments
I confirm that TwigPHP "and" token only evaluates the right operand if the left one is false. |
Can you link to an example on twigfiddle? |
@willrowe https://twigfiddle.com/3yjwsw My example above in a twigfiddle. The exception I get in twig.js is:
|
same problem here |
Same error when explicitly checking a undefined variable. However, with Interestingly if you use https://cdn.jsdelivr.net/npm/twig@1.13.3/twig.min.js in above fiddle it works. Looks like there's somewhere a regression. |
After further evaluation I suspect my comment above points to a different issue as it seem like the regression was just recently introduced - I created a dedicated issue for it: #679 |
I can confirm this is not working as expected, see this example: https://codepen.io/willrowe/pen/eYMeWqx However, it does not appear to be for the reasons originally outlined. The current version of twig.js throws the error: |
I am using twig.js with strict_variables set to true.
If I have a template like this:
and I loaded it with a completely empty context, I would expect no errors. This works in PHP Twig and what is recommended.
In twig.js, I get a TwigException:
It looks to me that twig.js is evaluating the truthiness of both operands even if the first one is false. I would not expect this, not only for this use case, but because JavaScript doesn't work this way either.
The workaround is this:
That makes the template harder to read and creates more indenting and whitespace then normal.
The text was updated successfully, but these errors were encountered: