Commit Graph

7886 Commits

Author SHA1 Message Date
Fabien Potencier b3cbcedced Move to PHPStan level 5 2026-02-23 15:07:49 +01:00
Fabien Potencier 825af0e7f1 Merge branch '3.x' into 4.x
* 3.x:
  Enforce more precise type on ListExpression
2026-02-23 15:07:05 +01:00
Fabien Potencier 206ad9f1a8 minor #4772 Enforce more precise type on ListExpression (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Enforce more precise type on ListExpression

Commits
-------

dcfc419a25 Enforce more precise type on ListExpression
2026-02-23 15:06:40 +01:00
Fabien Potencier dcfc419a25 Enforce more precise type on ListExpression 2026-02-23 13:36:14 +01:00
Fabien Potencier 0fa30e5f7f Add .phpunit.result.cache to .gitignore 2026-02-23 13:18:27 +01:00
Fabien Potencier b3eab38220 Remove deprecation notices 2026-02-23 13:07:28 +01:00
Fabien Potencier 23b4a48fa5 Merge branch '3.x' into 4.x
* 3.x:
  Deprecate passing non AbstractExpression nodes to MatchesBinary
2026-02-23 13:06:51 +01:00
Fabien Potencier f8fb235f47 feature #4771 Deprecate passing non AbstractExpression nodes to MatchesBinary (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate passing non AbstractExpression nodes to MatchesBinary

Commits
-------

379fb2faca Deprecate passing non AbstractExpression nodes to MatchesBinary
2026-02-23 13:06:23 +01:00
Fabien Potencier 379fb2faca Deprecate passing non AbstractExpression nodes to MatchesBinary 2026-02-23 11:40:51 +01:00
Fabien Potencier 9aefb837e0 Fix merge 2026-02-23 11:20:34 +01:00
Fabien Potencier b9d578d53f Merge branch '3.x' into 4.x
* 3.x:
  Deprecate passing a non-AbstractExpression node to Parser::setParent()
2026-02-23 11:13:55 +01:00
Fabien Potencier b8ff82d968 feature #4769 Deprecate passing a non-AbstractExpression node to Parser::setParent() (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate passing a non-AbstractExpression node to Parser::setParent()

Commits
-------

54d5c004b4 Deprecate passing a non-AbstractExpression node to Parser::setParent()
2026-02-23 11:11:09 +01:00
Fabien Potencier 54d5c004b4 Deprecate passing a non-AbstractExpression node to Parser::setParent() 2026-02-22 15:28:59 +01:00
Fabien Potencier 9a198ce169 Fix tests 2026-02-09 12:32:40 +01:00
Fabien Potencier 463ef4018d Merge branch '3.x' into 4.x
* 3.x:
  Update CHANGELOG
  Add `html_attr_relaxed` escaping strategy
  re-add mixed return type
  Support short-circuiting in null-safe operator chains
  Add support for renaming variables in object destructuring
  Update .gitattributes to remove splitsh.json
  Fix intro for operator precedence table ?
2026-02-09 12:29:34 +01:00
Fabien Potencier 0319c822d1 Update CHANGELOG 2026-02-08 19:02:26 +01:00
Fabien Potencier 751a187f07 feature #4748 Support short-circuiting in null-safe operator chains (HypeMC)
This PR was merged into the 3.x branch.

Discussion
----------

Support short-circuiting in null-safe operator chains

This PR adds short-circuiting for null-safe operator chains, using the same rules as PHP, `PropertyAccess`, and the `ExpressionLanguage`.

Previously, only the immediate null-safe access was guarded. With this change, as soon as a `null` is encountered at a null-safe access, the rest of the chain is skipped.

My approach was to move the null check outside of the `getAttribute()` calls so the expression can immediately return `null`, eg:

```twig
foo?.bar.baz
```

Before:

```php
yield $this->env
    ->getRuntime('Twig\Runtime\EscaperRuntime')
    ->escape(
        CoreExtension::getAttribute(
            $this->env,
            $this->source,
            (
                null === (
                    $_v0 = (
                        isset($context['foo']) || array_key_exists('foo', $context)
                            ? $context['foo']
                            : throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
                    )
                )
                    ? null
                    : CoreExtension::getAttribute(
                        $this->env,
                        $this->source,
                        $_v0,
                        'bar',
                        [],
                        'any',
                        false,
                        false,
                        false,
                        3
                    )
            ),
            'baz',
            [],
            'any',
            false,
            false,
            false,
            3
        ),
        'html',
        null,
        true
    );
```

Now:

```php
yield $this->env
    ->getRuntime('Twig\Runtime\EscaperRuntime')
    ->escape(
        (
            null === (
                $_v0 = (
                    isset($context['foo']) || array_key_exists('foo', $context)
                        ? $context['foo']
                        : throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
                )
            )
                ? null
                : CoreExtension::getAttribute(
                    $this->env,
                    $this->source,
                    CoreExtension::getAttribute(
                        $this->env,
                        $this->source,
                        $_v0,
                        'bar',
                        [],
                        'any',
                        false,
                        false,
                        false,
                        3
                    ),
                    'baz',
                    [],
                    'any',
                    false,
                    false,
                    false,
                    3
                )
        ),
        'html',
        null,
        true
    );
```

Commits
-------

d56e8e2dba Support short-circuiting in null-safe operator chains
2026-02-08 19:02:03 +01:00
Fabien Potencier afe8e19ecb feature #4743 Add html_attr_relaxed escaping strategy (mpdude)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Add `html_attr_relaxed` escaping strategy

This adds `html_attr_relaxed`, a relaxed variant of the `html_attr` escaping strategy. The difference is that `html_attr_relaxed` does not escape the `:`, `@`, `[` and `]` characters. These are used by some front-end frameworks in attribute names to wire special handling/value binding. See https://v2.vuejs.org/v2/guide/syntax.html#v-bind-Shorthand for an example.

The HTML 5 spec does not exclude all those characters from attribute names ([html.spec.whatwg.org/multipage/syntax.html#attributes-2](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2)).

However, at least XML processors will treat the colon as the XML namespace separator.

HTML 5 allows XML only on SVG and MathML elements, and only for pre-defined namespace-prefixes ([developer.mozilla.org/en-US/docs/Web/API/Attr/localName#:~:text=That means that the local,different from the qualified name](https://developer.mozilla.org/en-US/docs/Web/API/Attr/localName#:~:text=That%20means%20that%20the%20local,different%20from%20the%20qualified%20name)). For other something: prefixes, these will simply be passed on as part of the local attribute name.

According to [engine.sygnal.com/research/html5-attribute-names](https://engine.sygnal.com/research/html5-attribute-names), all current browser implementations handle at least the colon fine, and the aforementioned Vue.js documentation suggests that this is also the case for @.

Note also that Symfony UX only conditionally escapes attribute names, and it has `:` and `@` in its safe list:
https://github.com/symfony/ux/blob/c9a3e66b8ac53e870097e8a828913e57204398e7/src/TwigComponent/src/ComponentAttributes.php#L82

Closes #3614.

Commits
-------

04aa3df49f Add `html_attr_relaxed` escaping strategy
2026-02-08 18:59:10 +01:00
Matthias Pigulla 04aa3df49f Add html_attr_relaxed escaping strategy 2026-02-08 18:59:07 +01:00
Fabien Potencier df893829f2 feature #4759 Add support for renaming variables in object destructuring (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add support for renaming variables in object destructuring

Closes #4747

Commits
-------

3cc1b5233c Add support for renaming variables in object destructuring
2026-02-07 14:22:40 +01:00
Fabien Potencier 5fabdd0e6c minor #4764 re-add mixed return type (xabbuh)
This PR was merged into the 3.x branch.

Discussion
----------

re-add mixed return type

re-doing #4582, see https://github.com/symfony/symfony/actions/runs/21779345389/job/62840897500#step:8:3635

Commits
-------

3a903664a8 re-add mixed return type
2026-02-07 13:53:57 +01:00
Christian Flothmann 3a903664a8 re-add mixed return type 2026-02-07 13:41:32 +01:00
Fabien Potencier 3e213d14f3 minor #4625 [Doc] Fix intro for operator precedence table ? (hellomedia)
This PR was merged into the 3.x branch.

Discussion
----------

[Doc] Fix intro for operator precedence table ?

The table introductory paragraph says operator with lowest precedence are listed first ( I assume it means "listed first in the operator table" ).

However, the table starts with a precedence of 500, which seems to be the highest.

Am I completely misreading this ?

Commits
-------

26a12f73f2 Fix intro for operator precedence table ?
2026-02-07 10:12:40 +01:00
Fabien Potencier f502c9ed60 minor #4745 Update .gitattributes to remove splitsh.json (williamdes)
This PR was merged into the 3.x branch.

Discussion
----------

Update .gitattributes to remove splitsh.json

- Updated .gitattributes to remove splitsh.json

Commits
-------

79aecfbae0 Update .gitattributes to remove splitsh.json
2026-02-07 10:09:51 +01:00
Fabien Potencier d07442da9f Fix wrong merge 2026-02-07 09:26:41 +01:00
Fabien Potencier 2fe79e5f83 bug #4760 Fix PHPStan errors (fabpot)
This PR was merged into the 4.x branch.

Discussion
----------

Fix PHPStan errors

Commits
-------

058a381298 Fix PHPStan errors
2026-02-07 09:25:27 +01:00
Fabien Potencier 058a381298 Fix PHPStan errors 2026-02-07 09:21:55 +01:00
Fabien Potencier ec85153849 minor #4761 Fix tests (fabpot)
This PR was merged into the 4.x branch.

Discussion
----------

Fix tests

Commits
-------

2fba06cba9 Fix tests
2026-02-07 09:21:12 +01:00
Fabien Potencier 2fba06cba9 Fix tests 2026-02-07 09:18:21 +01:00
Fabien Potencier 1787147485 minor #4763 Fix CS (fabpot)
This PR was merged into the 4.x branch.

Discussion
----------

Fix CS

Commits
-------

cdce18d02a Fix CS
2026-02-07 09:17:49 +01:00
Fabien Potencier cdce18d02a Fix CS 2026-02-07 09:16:06 +01:00
Fabien Potencier df07638b63 Merge branch '3.x' into 4.x
* 3.x:
  Use stable versions of tools
2026-02-07 09:13:11 +01:00
Fabien Potencier 44093544e6 Use stable versions of tools 2026-02-07 09:12:49 +01:00
Fabien Potencier 0facb551b0 Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
2026-02-07 09:12:05 +01:00
Fabien Potencier 2c2d2fd435 minor #4762 Fix CS (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix CS

Commits
-------

861215c507 Fix CS
2026-02-07 09:10:10 +01:00
Fabien Potencier 861215c507 Fix CS 2026-02-07 09:07:38 +01:00
Fabien Potencier 99d77b1141 Remove versionadded in docs 2026-02-06 22:46:24 +01:00
Fabien Potencier 0222460a72 Merge branch '3.x' into 4.x
* 3.x:
  Bump version
  Add a not about the return value of destructuring
  Fix null-safe operator test
  Bump version
  Prepare the  release
  Update CHANGELOG
  Add support for object and mapping destructuring
  Rename classes
  Assignment operator array destructuring
  Fix doc notes
  Fix doc notes
  Add the = assignment operator
  Fix grammar and spelling mistakes in documentation
2026-02-06 22:45:48 +01:00
HypeMC d56e8e2dba Support short-circuiting in null-safe operator chains 2026-02-06 22:36:57 +01:00
Fabien Potencier eb516c9740 minor #4755 Add a not about the return value of destructuring (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add a not about the return value of destructuring

Commits
-------

c38868cdd0 Add a not about the return value of destructuring
2026-02-06 22:15:10 +01:00
Fabien Potencier 3cc1b5233c Add support for renaming variables in object destructuring 2026-02-06 22:12:59 +01:00
Fabien Potencier 09e6bb5a91 Bump version 2026-02-06 22:12:49 +01:00
Fabien Potencier c38868cdd0 Add a not about the return value of destructuring 2026-02-04 22:36:00 +01:00
Fabien Potencier 87848155a5 minor #4749 Fix null-safe operator test (HypeMC)
This PR was merged into the 3.x branch.

Discussion
----------

Fix null-safe operator test

Noticed this while working on #4748.

Without `strict_variables`, the tests always pass, even when the null-safe operator is not used.

Commits
-------

a16ac6bd35 Fix null-safe operator test
2026-01-27 11:37:59 +01:00
HypeMC a16ac6bd35 Fix null-safe operator test 2026-01-25 04:57:19 +01:00
Fabien Potencier 111b867703 Bump version 2026-01-23 22:27:43 +01:00
Fabien Potencier a64dc5d2cc Prepare the release v3.23.0 2026-01-23 22:00:41 +01:00
Fabien Potencier b0c42a9739 Update CHANGELOG 2026-01-23 22:00:23 +01:00
Fabien Potencier b609ae9d0d feature #4744 Add support for object and mapping destructuring (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add support for object and mapping destructuring

Refs https://github.com/twigphp/Twig/issues/3399

Commits
-------

8a0f8acbdf Add support for object and mapping destructuring
2026-01-23 12:57:17 +01:00
William Desportes 79aecfbae0 Update .gitattributes to remove splitsh.json 2026-01-22 09:55:32 +00:00