Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "Twig\Markup" instances in the "in" test (again) #3049

Merged
merged 1 commit into from Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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