harrydeluxe / php-liquid

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

Contains doesn't work if word is located at index 0 #26

Open QuentinBellus opened 10 years ago

QuentinBellus commented 10 years ago

Hi,

When using contains on a word located at index 0, the contains function doesn't work. Example:

 # myvar = 'my example'
  {% if myvar contains 'my' %}word found{% else %}not found {% endif %}

This will display "not found", which is wrong.

I believe the problem is located in the file "LiquidDecisionBlock.class.php", line 158:

case 'contains':
     return is_array($left) ? in_array($right, $left) : ($left == $right || strpos($left, $right));

Should be changed to:

case 'contains':
     return is_array($left) ? in_array($right, $left) : ($left == $right || strpos($left, $right)!==false);

Thanks.

SparK-Cruz commented 9 years ago

hmm... zero evaluates to false and breaks stuff

QuentinBellus commented 9 years ago

@SparK-Cruz Yes, hence the !== false. I changed it on my project and it works fine. After reporting this issue I found out some forks of this project also fixed it the same way (example).