minor #2469 Length filter non-mb_string on 7.x fix. (SpacePossum)

This PR was merged into the 1.x branch.

Discussion
----------

Length filter non-mb_string on 7.x fix.

follow up on https://github.com/twigphp/Twig/pull/2462
after https://github.com/twigphp/Twig/issues/2464#issuecomment-301014241

Commits
-------

3aa2e884 Length filter non-mb_string on 7.x fix.
This commit is contained in:
Fabien Potencier
2017-05-12 06:54:14 -07:00
+9 -1
View File
@@ -1363,6 +1363,10 @@ else {
*/
function twig_length_filter(Twig_Environment $env, $thing)
{
if (null === $thing) {
return 0;
}
if (is_scalar($thing)) {
return strlen($thing);
}
@@ -1371,7 +1375,11 @@ else {
return strlen((string) $thing);
}
return count($thing);
if ($thing instanceof \Countable || is_array($thing)) {
return count($thing);
}
return 1;
}
/**