Commit Graph

5154 Commits

Author SHA1 Message Date
Fabien Potencier fa405d760d bug #3397 Replace implicit dependence on ext/iconv in JS escaper (JoshyPHP)
This PR was merged into the 2.x branch.

Discussion
----------

Replace implicit dependence on ext/iconv in JS escaper

Twig's JS escaper fails on non-word characters if `ext/iconv` isn't available. That's because it uses iconv to replace characters with their hex codepoints and split characters outside the Basic Multilingual Plane into surrogate pairs. `symfony/polyfill-iconv` does not support the UTF-16BE conversion and cannot be used as a replacement.

This PR splits the surrogates using native PHP, after obtaining the codepoint via `mb_ord()` which is provided either natively or via `symfony/polyfill-mbstring`, which is already part of Twig's requirements.

Commits
-------

b77c2c40 Replace implicit dependence on ext/iconv in JS escaper
2020-09-14 15:15:14 +02:00
JoshyPHP b77c2c40b4 Replace implicit dependence on ext/iconv in JS escaper
polyfill-iconv does not support the UTF-16BE conversion
2020-09-13 19:23:45 +02:00
Fabien Potencier 7fdfbe8626 Fix typo 2020-08-24 12:05:56 +02:00
Fabien Potencier b48bd18dc6 Update CHANGELOG 2020-08-23 17:56:05 +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 11e429d23d bug #3349 Add test to verify that filter is not working when template_from_string (Bozhidar Hristov, fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Add test to verify that filter is not working when template_from_string

When using {{ include(sandboxed = true) }} in  conjunction with {{ template_from_string() }} - sandbox is not active.

Commits
-------

c7be1bb3 Fix sandbox support when using include(template_from_string())
04431228 Add test to verify that filter is not working when template_from_string is used.
2020-08-23 17:53:39 +02:00
Fabien Potencier c7be1bb3c4 Fix sandbox support when using include(template_from_string()) 2020-08-23 17:48:34 +02:00
Bozhidar Hristov 04431228af Add test to verify that filter is not working when template_from_string is used. 2020-08-23 17:46:12 +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 03491db322 Merge branch '1.x' into 2.x
* 1.x:
  Remove tests that do not make sense
2020-08-23 14:46:45 +02:00
Fabien Potencier 80a4a1f31e Remove tests that do not make sense 2020-08-23 14:46:38 +02:00
Fabien Potencier d97c34d1e5 Update CHANGELOG 2020-08-23 14:22:29 +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
Fabien Potencier df5d4c3aad Update CHANGELOG 2020-08-23 14:20:00 +02:00
Fabien Potencier d14dab78ce Fix previous merge 2020-08-23 14:19:17 +02:00
Fabien Potencier 7fb5d8ee34 feature #3255 Make round brackets optional for one argument tests like sameas (iquito)
This PR was submitted for the 3.x branch but it was squashed and merged into the 1.x branch instead.

Discussion
----------

Make round brackets optional for one argument tests like sameas

Currently Twig forces round brackets when doing tests with `is` if there is an argument:

    {{ 1 is same as(1) ? 'OK' }}
    {{ 8 is divisible by(2) ? 'OK' }}

That syntax always bumped me, because without the brackets it would be easier to understand and write, especially for people who do not know Twig internals:

    {{ 1 is same as 1 ? 'OK' }}
    {{ 8 is divisible by 2 ? 'OK' }}

Twig only has the `same as` and `divisible by` tests which need arguments (in the base library), and for both you usually only need one argument, so it could make the template syntax more concise. [Jinja already supports this syntax](https://jinja.palletsprojects.com/en/2.11.x/templates/#tests) for one argument tests, so it would be one less difference between Jinja and Twig for people who use both.

The changes in this pull request should be fully backwards-compatible - instead of Twig throwing a SyntaxError it now accepts one argument when the round brackets are missing. I added an option for TwigTest to signal that there is one mandatory argument for the test, otherwise the ExpressionParser does not know it should look for that mandatory argument, and this feature is therefore available to anybody writing their own TwigTests, which could help extensions to Twig to simplify their syntax too.

I also adjusted the unit tests for `sameas` and `divisibleby` in hopefully a sensible way.

Commits
-------

1ee72d9e Make round brackets optional for one argument tests like sameas
2020-08-23 14:16:43 +02:00
Andreas 1ee72d9e15 Make round brackets optional for one argument tests like sameas 2020-08-23 14:16:31 +02:00
Fabien Potencier 7c3f4ec8e9 Bump version 2020-08-23 14:01:50 +02:00
Fabien Potencier 77dcff7186 Merge branch '1.x' into 2.x
* 1.x:
  Bump version
  Tweak docs
  Update CHANGELOG
  Support object init from variable
2020-08-23 14:01:18 +02:00
Fabien Potencier c6927de9e7 Bump version 2020-08-23 13:59:06 +02:00
Fabien Potencier 244ef52df6 Tweak docs 2020-08-23 13:58:27 +02:00
Fabien Potencier b0ce4f64ba Update CHANGELOG 2020-08-23 13:56:44 +02:00
Fabien Potencier 6fe2924795 feature #3277 Support object initialisation shortcut {a} == {a:a} from ES2015 (GromNaN)
This PR was submitted for the 3.x branch but it was merged into the 1.x branch instead.

Discussion
----------

Support object initialisation shortcut {a} == {a:a} from ES2015

Object declaration in Twig is very close to the Javascript syntax and is targeting the same profil of developers. In order to provide a smooth developer experience, Twig should implement some new feature of ECMAScript.

Since ECMAScript 2015, a short syntax can be used to declare an object when the key is identical to a defined variable (see [MDN doc](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Object_initializer))

```js
// Shorthand property names (ES2015)
let a = 'foo', b = 42, c = {};
let o = {a, b, c}
```

This PR adds the same syntax to Twig.
This can be very useful for `include ... with ... only` :
```twig
{% set title = "My title" %}
{% set image = "image.jpg" %}
{{ include "template.twig" with {title, image} only }}
# instead of
{{ include "template.twig" with {title: title, image: image} only }}
```

Commits
-------

133edb36 Support object init from variable
2020-08-23 13:55:00 +02:00
Jérôme TAMARELLE 133edb3696 Support object init from variable
{a} is a shortcut for {a:a}
From ECMAScript 2015 syntax https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Object_initializer
2020-08-23 13:54:49 +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
Fabien Potencier bde54e11b8 Fix CS 2020-08-23 13:48:32 +02:00
Fabien Potencier 93390aebd3 Merge branch '1.x' into 2.x
* 1.x:
  Migrate more tests
  Update phpunit config
2020-08-23 13:44:00 +02:00
Fabien Potencier 2c7cad3416 minor #3390 More PHPUnit fixes (fabpot)
This PR was squashed before being merged into the 1.x branch.

Discussion
----------

More PHPUnit fixes

Commits
-------

f787c032 Migrate more tests
ad8d012e Update phpunit config
2020-08-23 13:43:11 +02:00
Fabien Potencier f787c032ab Migrate more tests 2020-08-23 12:47:51 +02:00
Fabien Potencier ad8d012e20 Update phpunit config 2020-08-23 12:46:19 +02:00
Fabien Potencier f7ce885a02 Merge branch '1.x' into 2.x
* 1.x:
  Update phpunit assertion
2020-08-23 12:31:37 +02:00
Fabien Potencier a293147027 minor #3389 Update phpunit assertion (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Update phpunit assertion

Commits
-------

e5882d9f Update phpunit assertion
2020-08-23 12:30:49 +02:00
Fabien Potencier e5882d9fb4 Update phpunit assertion 2020-08-23 12:22:59 +02:00
Fabien Potencier b531196d8c bug #3388 Fixed Twig\Template check (brandonkelly)
This PR was merged into the 2.x branch.

Discussion
----------

Fixed Twig\Template check

Looks like this was missed when the `Twig\Template` class was added, and `Twig_Template` was deprecated + aliased.

Commits
-------

67bff7b7 Fixed Twig\Template check
2020-08-13 16:11:59 +02:00
Brandon Kelly 67bff7b7c9 Fixed Twig\Template check 2020-08-13 06:50:55 -07:00
Fabien Potencier 76f8ead7ef Bump version to 2.13.2-DEV 2020-08-05 17:10:06 +02:00
Fabien Potencier 57e9625977 Prepare the 2.13.1 release v2.13.1 2020-08-05 17:09:04 +02:00
Fabien Potencier f48f94a358 Update CHANGELOG 2020-08-05 17:08:12 +02:00
Fabien Potencier bf68fa6d22 Merge branch '1.x' into 2.x
* 1.x:
  Bump version to 1.43.2-DEV
  Prepare the 1.43.1 release
  Update CHANGELOG
2020-08-05 17:08:01 +02:00
Fabien Potencier 4ba9822987 Bump version to 1.43.2-DEV 2020-08-05 17:06:12 +02:00
Fabien Potencier 2311602f6a Prepare the 1.43.1 release v1.43.1 2020-08-05 17:05:05 +02:00
Fabien Potencier 5383d354d3 Update CHANGELOG 2020-08-05 17:00:10 +02:00
Fabien Potencier 38bd74d03a Merge branch '1.x' into 2.x
* 1.x:
  Add a test
  fix typo in ApplyTokenParser PHP doc
  Fixes #3351
2020-08-05 16:53:59 +02:00
Fabien Potencier 94aa9bf305 Add a test 2020-08-05 16:53:34 +02:00
Fabien Potencier bf3cc60121 Fix typo 2020-07-29 08:07:51 +02:00
Fabien Potencier 1a95a0bafe minor #3377 Macro not available in embed tags (GromNaN)
This PR was merged into the 2.x branch.

Discussion
----------

Macro not available in embed tags

Macro imported globally in a template via `import` or `from` are not available inside `embed` tags.
This behavior is present since Twig v2.0.0. I think it needs to be documented. Feel free to suggest an other text.

Here is some example :

- If the macro is imported globally, it's not available inside the `embed` tag, we get an error : https://twigfiddle.com/jwtwm3
```twig
{% import 'macro.twig' as macro %}
{% embed 'embed.twig' %}
    {% block content %}
        {{ macro.sayhello('Jérôme') }}
    {% endblock %}
{% endembed %}
```
- Whereas is the macro is imported inside the `embed` tag, it's available in its `block` tags : https://twigfiddle.com/jwtwm3/2
```twig
{% embed 'embed.twig' %}
    {% import 'macro.twig' as macro %}
    {% block content %}
        {{ macro.sayhello('Jérôme') }}
    {% endblock %}
{% endembed %}
```

Commits
-------

be291441 Update doc for macro with embed tags
2020-07-29 08:07:02 +02:00
Fabien Potencier c0ec6c9c01 minor #3378 Fix compatibility with PHPUnit 9 (GromNaN)
This PR was merged into the 2.x branch.

Discussion
----------

Fix compatibility with PHPUnit 9

Commits
-------

9a83f7ed Fix compatibility with PHPUnit 10
2020-07-29 07:50:05 +02:00
Jérôme TAMARELLE 9a83f7edf6 Fix compatibility with PHPUnit 10 2020-07-29 03:03:03 +02:00