mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
Fixed "in" operator
This commit is contained in:
@@ -893,15 +893,15 @@ function twig_sort_filter($array)
|
||||
function twig_in_filter($value, $compare)
|
||||
{
|
||||
if (is_array($compare)) {
|
||||
return in_array($value, $compare, is_object($value));
|
||||
return in_array($value, $compare, true);
|
||||
} elseif (is_string($compare)) {
|
||||
if (!strlen($value)) {
|
||||
return empty($compare);
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false !== strpos($compare, (string) $value);
|
||||
return '' === $value || false !== strpos($compare, $value);
|
||||
} elseif ($compare instanceof Traversable) {
|
||||
return in_array($value, iterator_to_array($compare, false), is_object($value));
|
||||
return in_array($value, iterator_to_array($compare, false), true);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -33,8 +33,23 @@ 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'))
|
||||
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'dir_name' => dirname(__FILE__), 'dir_object' => new SplFileInfo(dirname(__FILE__)))
|
||||
--EXPECT--
|
||||
TRUE
|
||||
TRUE
|
||||
@@ -45,4 +60,18 @@ TRUE
|
||||
TRUE
|
||||
TRUE
|
||||
TRUE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
TRUE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
FALSE
|
||||
TRUE
|
||||
FALSE
|
||||
FALSE
|
||||
|
||||
Reference in New Issue
Block a user