kalimatas / php-liquid

A PHP port of Ruby's Liquid Templates
http://www.delacap.com/artikel/Liquid-Templates/
MIT License
169 stars 59 forks source link

If statement ignoring parenthesis #215

Open Nixon-Joseph opened 7 months ago

Nixon-Joseph commented 7 months ago

I had the following if statement:

{% if (model.Friends.size == nil or model.Friends.size <= 0) and (model.PendingFriends == nil or model.PendingFriends.size <= 0) %}
    <div>
        <h2 class="text-muted">#No Friends</h2>
        <p class="text-muted">You have no friends on this platform yet. Don't worry, I'm sure you'll make some!</p>
    </div>
{% endif %}

And this was ALWAYS showing the result, because PendingFriends was always an empty array, even though Friends wasn't empty.

Checking for either case individually worked as expected, but putting together a couple of grouped ORs with an AND via parenthesis did not work as expected.

PHP: 8.x Liquid: 1.4.42 OS: Linux -> LAMP stack

If I'm just missing something, let me know, but removing the nil checks makes it work as expected (just less safe).