mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
minor #4272 Validate the input of CoreExtension::map() (derrabus)
This PR was merged into the 3.x branch.
Discussion
----------
Validate the input of CoreExtension::map()
Fixes https://github.com/twigphp/Twig/pull/4269#discussion_r1742182828
As discovered in #4269, we have a test that checks if the map filter fails if we pass a non-iterable value. However, this test relies on an active error handler that throws on PHP warnings.
This PR adds input validation the the `map()` function like we can already find it in similar functions.
Commits
-------
a035204a Validate the input of CoreExtension::map()
This commit is contained in:
@@ -1833,6 +1833,10 @@ final class CoreExtension extends AbstractExtension
|
||||
*/
|
||||
public static function map(Environment $env, $array, $arrow)
|
||||
{
|
||||
if (!is_iterable($array)) {
|
||||
throw new RuntimeError(\sprintf('The "map" filter expects a sequence/mapping or "Traversable", got "%s".', get_debug_type($array)));
|
||||
}
|
||||
|
||||
self::checkArrowInSandbox($env, $arrow, 'map', 'filter');
|
||||
|
||||
$r = [];
|
||||
|
||||
Reference in New Issue
Block a user