mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 20:16:45 +00:00
Throws proper Twig exception when using cycle on an empty array
This commit is contained in:
@@ -329,6 +329,10 @@ final class CoreExtension extends AbstractExtension
|
||||
return $values;
|
||||
}
|
||||
|
||||
if (!\count($values)) {
|
||||
throw new RuntimeError('The "cycle" function does not work on empty arrays');
|
||||
}
|
||||
|
||||
return $values[$position % \count($values)];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
"cycle" function returns an error on empty arrays
|
||||
--TEMPLATE--
|
||||
{{ cycle([], 0) }}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\RuntimeError: The "cycle" function does not work on empty arrays in "index.twig" at line 2
|
||||
Reference in New Issue
Block a user