Skip to content
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

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

Open
QuentinBellus opened this issue Sep 10, 2014 · 2 comments
Open

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

QuentinBellus opened this issue Sep 10, 2014 · 2 comments

Comments

@QuentinBellus
Copy link
Contributor

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
Copy link

hmm... zero evaluates to false and breaks stuff

@QuentinBellus
Copy link
Contributor Author

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants