Commit Graph

178 Commits

Author SHA1 Message Date
Ryan Weaver ba4fe3ba34 Adding support for the ...spread operator on arrays and hashes 2023-07-20 16:08:57 +02:00
Jacob Richardson f136668933 Restores the leniency of the matches twig comparison, allowing null subject to result in a non-match.
Resolves BC break introduced in PR https://github.com/twigphp/Twig/pull/3687

As per pattern in https://github.com/twigphp/Twig/pull/3617
2023-02-07 17:07:16 +00:00
ju1ius 4f2f3f814e pass the current key to reduce filter's callback 2023-01-25 10:42:37 +01:00
Christophe Coevoet 44c46712b8 Fix error messages in sandboxed mode for has some and has every 2023-01-03 18:06:19 +01:00
Fabien Potencier a82e94d911 Add some tests 2022-12-27 12:31:54 +01:00
Matheo Daninos 61672c43f9 throwing syntaxt error when the matches regexp is not valid 2022-12-27 12:25:33 +01:00
Fabien Potencier d769ae90d1 feature #3670 Add "some" and "every" filters (Jean-Beru)
This PR was merged into the 3.x branch.

Discussion
----------

Add "some" and "every" filters

This PR adds 2 new tests inspired from Javascript's functions: [some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) and [every](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).

Usage :
```twig
Value {{ ([1, 2, 3] has some v => v == 2) ? 'found' : 'not found' }}

Key {{ ([1, 2, 3] has some (v, k) => k == 2) ? 'found' : 'not found' }}

Every values {{ ([1, 2, 3] has every v => 42 > v) ? 'match' : 'do not match' }}

Every keys {{ ([1, 2, 3] has every (v, k) => 42 > k) ? 'match' : 'do not match' }}
```

Commits
-------

009bb4fd Add "some" and "every" filters
2022-12-26 17:18:29 +01:00
Fabien Potencier fe347bbf1b Merge branch '2.x' into 3.x
* 2.x:
  Fix tests
  Updates CoreExtension::twig_constant to check for definition first to avoid hard crash
2022-12-26 16:12:53 +01:00
Alex Henderson-Roche 56b31224bd Updates CoreExtension::twig_constant to check for definition first to avoid hard crash 2022-12-26 13:36:01 +01:00
hubert.lenoir 009bb4fd82 Add "some" and "every" filters 2022-03-25 11:04:50 +01:00
Kévin Dunglas 0d6bd45844 add support for the class constant on objects 2022-03-25 09:58:48 +01:00
Fabien Potencier 9e5ca747b6 Merge branch '2.x' into 3.x
* 2.x:
  Disallow non closures in `sort` filter when the sanbox mode is enabled
2022-02-04 07:56:23 +01:00
Fabien Potencier 2eb3308055 Disallow non closures in sort filter when the sanbox mode is enabled 2022-02-04 07:52:21 +01:00
Fabien Potencier 5981815757 Merge branch '2.x' into 3.x
* 2.x:
  Rename variables used in map method
  The deprecated null value for the method round has been changed to zero.
2022-01-14 12:47:50 +01:00
v.arsentev 7d0e5d6a1e The deprecated null value for the method round has been changed to zero. 2022-01-11 16:12:44 +01:00
Fabien Potencier 1231fd4096 Merge branch '2.x' into 3.x
* 2.x:
  Allow null for nl2br, striptags and format filters
2022-01-03 17:03:55 +01:00
Ruud Kamphuis e9cd55def5 Allow null for nl2br, striptags and format filters
Same as https://github.com/twigphp/Twig/pull/3617
2022-01-03 14:28:28 +01:00
Fabien Potencier ec23eba2ad Merge branch '2.x' into 3.x
* 2.x:
  Add 8.1 in tests
  Allow null when Twig expects a string
2022-01-02 17:23:10 +01:00
Fabien Potencier 92bc110bcf Allow null when Twig expects a string 2022-01-02 16:05:53 +01:00
Fabien Potencier ed29f0010f Merge branch '2.x' into 3.x
* 2.x:
  Add ReturnTypeWillChange to JsonSerializable implementation
  Fix implicit flot to int casts
2021-06-06 18:31:44 +02:00
Fabien Potencier 7926399e0a Merge branch '1.x' into 2.x
* 1.x:
  Fix implicit flot to int casts
2021-06-06 18:31:25 +02:00
Alexander M. Turek de9cd76d7c Fix implicit flot to int casts 2021-06-06 00:32:22 +02:00
Maurício Meneghini Fauth 1783298bb8 Replace secure.php.net with www.php.net
See: https://news-web.php.net/php.internals/104533

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2021-05-18 16:07:51 -03:00
Fabien Potencier 9e6e700f96 minor #3509 Some code style fixes (dionisvl)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Some code style fixes

Fixes that:
- Type cast is unnecessary
- Unnecessary curly braces syntax for variable
- Operations priority might differ that except

Commits
-------

17c6371f Some code style fixes
2021-05-14 10:26:10 +02:00
Den 17c6371fb5 Some code style fixes 2021-05-14 10:26:05 +02:00
Fabien Potencier fcbaa669ab Fix CS 2021-05-12 09:47:40 +02:00
Fabien Potencier 2dd1d909b9 Fix CS 2021-05-12 09:37:17 +02:00
Fabien Potencier 59f3e8e5dc Fix CS 2021-05-12 09:19:37 +02:00
Fabien Potencier 94b7c1c2f6 Merge branch '2.x' into 3.x
* 2.x:
  Fix CS
  added PHP 8.1 as experimental
2021-03-22 09:23:56 +01:00
Fabien Potencier 116bfb0bc9 Merge branch '1.x' into 2.x
* 1.x:
  Fix CS
2021-03-22 09:23:49 +01:00
Fabien Potencier 9773024395 Fix CS 2021-03-22 09:23:44 +01:00
Fabien Potencier 0b103dfeb0 Merge branch '1.x' into 2.x
* 1.x:
  added PHP 8.1 as experimental
2021-03-22 09:23:06 +01:00
Oleg Andreyev bef89dcc1e added PHP 8.1 as experimental 2021-03-22 09:19:53 +01:00
Fabien Potencier 1327db55e9 Merge branch '2.x' into 3.x
* 2.x:
  Update format_time.rst
  Fix "include(template_from_string())"
  Fix PHPUnit config
2020-10-27 15:15:09 +01:00
Fabien Potencier 497f027cd4 Merge branch '1.x' into 2.x
* 1.x:
  Fix "include(template_from_string())"
  Fix PHPUnit config
2020-10-27 15:14:55 +01:00
Fabien Potencier 9fb2deee6e bug #3413 Fix "include(template_from_string())" when not using a sandbox (fabpot)
This PR was squashed before being merged into the 1.x branch.

Discussion
----------

Fix "include(template_from_string())" when not using a sandbox

Closed #3411

Commits
-------

df9c9f21 Fix "include(template_from_string())"
3d91e335 Fix PHPUnit config
2020-10-27 15:14:35 +01:00
Fabien Potencier 3078be718c Fix CS 2020-10-27 13:53:45 +01:00
Fabien Potencier df9c9f2165 Fix "include(template_from_string())" 2020-10-27 13:39:31 +01:00
Fabien Potencier 67eea1843b Backport #3397 2020-09-14 15:17:28 +02:00
Fabien Potencier 1fb577363d Merge branch '2.x' into 3.x
* 2.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:24 +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 c7be1bb3c4 Fix sandbox support when using include(template_from_string()) 2020-08-23 17:48:34 +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 7759111e75 Merge branch '2.x' into 3.x
* 2.x:
  Update CHANGELOG
  Update CHANGELOG
  Fix previous merge
  Make round brackets optional for one argument tests like sameas
2020-08-23 14:22:39 +02:00
Fabien Potencier 9bf49d5ccf Merge branch '1.x' into 2.x
* 1.x:
  Update CHANGELOG
  Fix previous merge
  Make round brackets optional for one argument tests like sameas
2020-08-23 14:22:09 +02:00
Andreas 1ee72d9e15 Make round brackets optional for one argument tests like sameas 2020-08-23 14:16:31 +02:00
Fabien Potencier 222d053733 Merge branch '2.x' into 3.x
* 2.x:
  Fix CS
  Fix CS
2020-08-23 13:49:50 +02:00
Fabien Potencier cb3a8a25d0 Fix CS 2020-08-23 13:49:43 +02:00
Fabien Potencier 81612a5c7d Merge branch '1.x' into 2.x
* 1.x:
  Fix CS
2020-08-23 13:49:18 +02:00