fixed previous commit
authorFabien Potencier <fabien.potencier@gmail.com>
Sat, 29 Oct 2011 13:12:58 +0000 (15:12 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Sat, 29 Oct 2011 13:13:27 +0000 (15:13 +0200)
lib/Twig/Extension/Core.php
test/Twig/Tests/Fixtures/tests/in.test

index 3aae743..1b89aa8 100644 (file)
@@ -443,8 +443,8 @@ function twig_in_filter($value, $compare)
     if (is_array($compare)) {
         return in_array($value, $compare);
     } elseif (is_string($compare)) {
-        if (!$compare) {
-            return empty($value);
+        if (!strlen((string) $value)) {
+            return empty($compare);
         }
         return false !== strpos($compare, (string) $value);
     } elseif (is_object($compare) && $compare instanceof Traversable) {
index ba40f25..45c72fd 100644 (file)
@@ -12,12 +12,27 @@ TRUE
 {% else %}
 TRUE
 {% endif %}
-{% if '' not in foo %}
+{% if 'a' in bar %}
+TRUE
+{% endif %}
+{% if 'c' not in bar %}
+TRUE
+{% endif %}
+{% if '' not in bar %}
 TRUE
 {% endif %}
 {% if '' in '' %}
 TRUE
 {% endif %}
+{% if '0' not in '' %}
+TRUE
+{% endif %}
+{% if 'a' not in '0' %}
+TRUE
+{% endif %}
+{% if '0' in '0' %}
+TRUE
+{% endif %}
 --DATA--
 return array('bar' => 'bar', 'foo' => array('bar' => 'bar'))
 --EXPECT--
@@ -26,3 +41,8 @@ TRUE
 TRUE
 TRUE
 TRUE
+TRUE
+TRUE
+TRUE
+TRUE
+TRUE