Commit Graph

12 Commits

Author SHA1 Message Date
Drew Richards 85bf01b4ab Catch errors thrown during template rendering 2023-10-26 17:55:48 -07:00
Fabien Potencier 157fa56829 Merge branch '1.x' into 2.x
* 1.x:
  Fix CS
  Migrate to the new PHP CS Fixer config file
2021-05-12 09:27:30 +02:00
Fabien Potencier 59f3e8e5dc Fix CS 2021-05-12 09:19:37 +02:00
Fabien Potencier ab6695b580 Merge branch '1.x' into 2.x
* 1.x:
  Fix sandbox support when using include(template_from_string())
  Add test to verify that filter is not working when template_from_string is used.
  In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError
2020-08-23 17:55:14 +02:00
Fabien Potencier 54eff0d96e bug #3341 In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError (thijzert)
This PR was squashed before being merged into the 1.x branch.

Discussion
----------

In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError

If a template accidentally performs `|filter(...)` on a variable that isn't traversable (e.g. `null`), the calling code will encouter the raw `TypeError` that results from Twig trying to construct an `IteratorIterator` on that variable. This means that context information (e.g., in which exact template the error occurred, and on which line) is discarded, which makes it very difficult to debug your templates.

This commit adds code to throw a `RuntimeError` if Twig encounters a situation where there's no valid way to filter an array.

Commits
-------

567b1e2a In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError
2020-08-23 16:40:19 +02:00
Thijs van Dijk 567b1e2a06 In |filter(), |map(), and |reduce(), throw a RuntimeError instead of a TypeError 2020-08-23 16:40:13 +02:00
Fabien Potencier bde54e11b8 Fix CS 2020-08-23 13:48:32 +02:00
Fabien Potencier c38f96318b Fix CS 2020-06-22 08:15:56 +02:00
Fabien Potencier c829dafd75 Merge branch '1.x' into 2.x
* 1.x:
  Update to PhpUnitBridge and fix deprecations
2019-08-08 10:19:01 +02:00
Jérémy Derussé b776e41f5a Update to PhpUnitBridge and fix deprecations 2019-08-08 09:39:49 +02:00
Fabien Potencier 1e3bb75010 moved test under tests/ 2019-06-30 14:51:54 +02:00
Fabien Potencier 22a1317249 moved tests under tests/ 2019-06-30 14:48:27 +02:00