From cf6116c2a8ac340fbe274761bb896729c131201e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 29 Oct 2011 15:12:58 +0200 Subject: [PATCH] fixed previous commit --- lib/Twig/Extension/Core.php | 4 ++-- test/Twig/Tests/Fixtures/tests/in.test | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 3aae743..1b89aa8 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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) { diff --git a/test/Twig/Tests/Fixtures/tests/in.test b/test/Twig/Tests/Fixtures/tests/in.test index ba40f25..45c72fd 100644 --- a/test/Twig/Tests/Fixtures/tests/in.test +++ b/test/Twig/Tests/Fixtures/tests/in.test @@ -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 -- 1.7.2.5