Skip to content

Commit

Permalink
added support for "Twig\Markup" instances in the "in" test (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 3, 2019
1 parent 51f33f7 commit 2218cfe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,5 +1,6 @@
* 1.42.1 (2019-XX-XX)

* added support for "Twig\Markup" instances in the "in" test (again)
* allowed string operators as variables names in assignments

* 1.42.0 (2019-05-31)
Expand Down
3 changes: 3 additions & 0 deletions src/Extension/CoreExtension.php
Expand Up @@ -943,6 +943,9 @@ function twig_in_filter($value, $compare)
if ($value instanceof Markup) {
$value = (string) $value;
}
if ($compare instanceof Markup) {
$compare = (string) $compare;
}

if (\is_array($compare)) {
return \in_array($value, $compare, \is_object($value) || \is_resource($value));
Expand Down
2 changes: 2 additions & 0 deletions test/Twig/Tests/Fixtures/tests/in.test
Expand Up @@ -56,6 +56,7 @@ Twig supports the in operator
{{ '5.5' in 125.5 ? 'KO' : 'OK' }}

{{ safe in ['foo', 'bar'] ? 'OK' : 'KO' }}
{{ 'fo' in safe ? 'OK' : 'KO' }}
--DATA--
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--
Expand Down Expand Up @@ -114,3 +115,4 @@ OK
OK

OK
OK

0 comments on commit 2218cfe

Please sign in to comment.