diff --git a/CHANGELOG b/CHANGELOG index 2ef8dd68d..ea23a1f30 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.39.2 (2019-XX-XX) + * added support for "Twig\Markup" instances in the "in" test * fixed Lexer when using custom options containing the # char * fixed "import" when macros are stored in a template string diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 37301dfd4..e47e7cef1 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -935,6 +935,10 @@ function twig_sort_filter($array) */ function twig_in_filter($value, $compare) { + if ($value instanceof Markup) { + $value = (string) $value; + } + if (\is_array($compare)) { return \in_array($value, $compare, \is_object($value) || \is_resource($value)); } elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) { diff --git a/test/Twig/Tests/Fixtures/tests/in.test b/test/Twig/Tests/Fixtures/tests/in.test index 5c3071d5d..9241ae866 100644 --- a/test/Twig/Tests/Fixtures/tests/in.test +++ b/test/Twig/Tests/Fixtures/tests/in.test @@ -73,8 +73,10 @@ TRUE {{ 5.5 in 125.5 ? 'TRUE' : 'FALSE' }} {{ 5.5 in '125.5' ? 'TRUE' : 'FALSE' }} {{ '5.5' in 125.5 ? 'TRUE' : 'FALSE' }} + +{{ safe in ['foo', 'bar'] ? 'TRUE' : 'FALSE' }} --DATA-- -return ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'dir_object' => new \SplFileInfo(dirname(__FILE__)), 'object' => new \stdClass(), 'resource' => opendir(dirname(__FILE__))] +return ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'dir_object' => new \SplFileInfo(dirname(__FILE__)), 'object' => new \stdClass(), 'resource' => opendir(dirname(__FILE__)), 'safe' => new \Twig\Markup('foo', 'UTF-8')] --EXPECT-- TRUE TRUE @@ -126,3 +128,5 @@ TRUE FALSE TRUE FALSE + +TRUE