From a7edb17646cb09e3563f6dd402e0ee15b8e79255 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 16 Oct 2014 20:28:23 +0200 Subject: [PATCH] Revert "bug #1470 Fixed "in" operator (hason)" This reverts commit 5b172b5175e5985d144cc59985627d8820d32260, reversing changes made to 0d0cdba3bb239efa20a0bd0c4a890a41d529d672. --- lib/Twig/Extension/Core.php | 10 +++++----- test/Twig/Tests/Fixtures/tests/in.test | 31 +------------------------------ 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 50af07b..e71d741 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -930,15 +930,15 @@ function twig_sort_filter($array) function twig_in_filter($value, $compare) { if (is_array($compare)) { - return in_array($value, $compare, true); + return in_array($value, $compare, is_object($value)); } elseif (is_string($compare)) { - if (!is_string($value)) { - return false; + if (!strlen($value)) { + return empty($compare); } - return '' === $value || false !== strpos($compare, $value); + return false !== strpos($compare, (string) $value); } elseif ($compare instanceof Traversable) { - return in_array($value, iterator_to_array($compare, false), true); + return in_array($value, iterator_to_array($compare, false), is_object($value)); } return false; diff --git a/test/Twig/Tests/Fixtures/tests/in.test b/test/Twig/Tests/Fixtures/tests/in.test index 73445f8..45c72fd 100644 --- a/test/Twig/Tests/Fixtures/tests/in.test +++ b/test/Twig/Tests/Fixtures/tests/in.test @@ -33,23 +33,8 @@ TRUE {% if '0' in '0' %} TRUE {% endif %} -{{ false in [0, 1] ? 'TRUE' : 'FALSE' }} -{{ true in [0, 1] ? 'TRUE' : 'FALSE' }} -{{ '0' in [0, 1] ? 'TRUE' : 'FALSE' }} -{{ '' in [0, 1] ? 'TRUE' : 'FALSE' }} -{{ 0 in ['', 1] ? 'TRUE' : 'FALSE' }} -{{ '' in 'foo' ? 'TRUE' : 'FALSE' }} -{{ 0 in 'foo' ? 'TRUE' : 'FALSE' }} -{{ false in 'foo' ? 'TRUE' : 'FALSE' }} -{{ true in '100' ? 'TRUE' : 'FALSE' }} -{{ [] in 'Array' ? 'TRUE' : 'FALSE' }} -{{ [] in [true, false] ? 'TRUE' : 'FALSE' }} -{{ [] in [true, ''] ? 'TRUE' : 'FALSE' }} -{{ [] in [true, []] ? 'TRUE' : 'FALSE' }} -{{ dir_object in 'foo'~dir_name ? 'TRUE' : 'FALSE' }} -{{ 5 in 125 ? 'TRUE' : 'FALSE' }} --DATA-- -return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'dir_name' => dirname(__FILE__), 'dir_object' => new SplFileInfo(dirname(__FILE__))) +return array('bar' => 'bar', 'foo' => array('bar' => 'bar')) --EXPECT-- TRUE TRUE @@ -60,18 +45,4 @@ TRUE TRUE TRUE TRUE -FALSE -FALSE -FALSE -FALSE -FALSE TRUE -FALSE -FALSE -FALSE -FALSE -FALSE -FALSE -TRUE -FALSE -FALSE -- 1.7.2.5