Commit Graph

8206 Commits

Author SHA1 Message Date
Fabien Potencier d5e2f249d2 Remove deprecated macro defined test syntax 2026-07-31 12:18:02 +02:00
Fabien Potencier ab8e41b49b Merge branch '3.x' into 4.x
* 3.x:
  Deprecate using parentheses when testing a macro with the defined test

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	src/ExpressionParser/Infix/DotExpressionParser.php
#	src/ExpressionParser/Infix/FunctionExpressionParser.php
#	src/ExpressionParser/Infix/IsExpressionParser.php
#	tests/Fixtures/macros/call_without_parentheses.legacy.test
#	tests/ParserTest.php
2026-07-31 12:15:12 +02:00
Fabien Potencier 7793b6153f feature #4878 Deprecate using parentheses when testing a macro with the defined test (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Deprecate using parentheses when testing a macro with the defined test

Commits
-------

34d9c67d38 Deprecate using parentheses when testing a macro with the defined test
2026-07-31 12:09:26 +02:00
Fabien Potencier 34d9c67d38 Deprecate using parentheses when testing a macro with the defined test 2026-07-31 12:09:23 +02:00
Fabien Potencier ce013c063e Remove deprecated code 2026-07-30 14:14:10 +02:00
Fabien Potencier efd847f456 Fix merge conflict resolution 2026-07-30 14:04:07 +02:00
Fabien Potencier 986a765019 Merge branch '3.x' into 4.x
* 3.x:
  Redesign macro calls and argument handling

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	src/ExpressionParser/Infix/ArgumentsTrait.php
#	src/ExpressionParser/Infix/DotExpressionParser.php
#	src/ExpressionParser/Infix/FunctionExpressionParser.php
#	src/Extension/CoreExtension.php
#	src/Node/Expression/MacroReferenceExpression.php
#	src/Node/Expression/MethodCallExpression.php
#	src/Node/Expression/TempNameExpression.php
#	src/Node/MacroNode.php
#	src/Node/ModuleNode.php
#	src/Template.php
#	tests/Fixtures/macros/call_without_parentheses.legacy.test
#	tests/Node/Expression/MacroReferenceTest.php
#	tests/Node/MacroTest.php
2026-07-30 14:02:30 +02:00
Fabien Potencier 6dfc7961a2 feature #4851 Redesign macro calls and argument handling (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Redesign macro calls and argument handling

This is my attempt to make macros "better". It uses modern PHP features that didn't exist when I designed macros a long time ago.

The first objective is to close the gap between their behavior and the behavior of Twig callables: functions, filters, and tests.

Here are some important changes:

* Calling a macro without passing a value for an argument that has no default value is deprecated; it is currently silently passed as `null`.
* Passing extra positional arguments or unknown named arguments to a macro without an explicit variadic argument is deprecated; these arguments are currently silently accepted through the implicit `varargs` variable.
* Explicit variadic macro arguments are now supported with `...name`.
* Macros are compiled as closures stored in the macro registry, instead of public generated `macro_*` methods.

The refactor introduces `TwigMacro` and `MacroArgument` to represent template-defined macros with an explicit signature, similar to the existing Twig callable model.

Commits
-------

d7f8b4eb1c Redesign macro calls and argument handling
2026-07-30 13:53:27 +02:00
Fabien Potencier d7f8b4eb1c Redesign macro calls and argument handling 2026-07-30 13:53:24 +02:00
Fabien Potencier b34f022583 Remove deprecated code 2026-07-30 13:52:37 +02:00
Fabien Potencier feffcb7df8 Fix merge conflict resolution 2026-07-30 13:32:38 +02:00
Fabien Potencier 3197df7b5e Merge branch '3.x' into 4.x
* 3.x:
  Make the sandbox a first-class citizen with a dedicated Sandbox class

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	doc/tags/sandbox.rst
#	phpstan-baseline.neon
#	src/Extension/CoreExtension.php
#	src/Extension/SandboxExtension.php
#	src/Sandbox/SecurityPolicy.php
2026-07-30 13:04:50 +02:00
Fabien Potencier e315d6d396 feature #4854 Make the sandbox a first-class citizen with a dedicated Sandbox class (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Make the sandbox a first-class citizen with a dedicated Sandbox class

I've been thinking about making the sabdbox feature as a first class citizen for years. With all the work that has been done recently on security issues, I spent some time on it again. Here is the result.

The main ideas:

* Currently, the sandbox is thigtly coupled to the "main" environment: `SandboxExtension` is registered on the environmen directly, so it instruments all compiled template, and adds runtime checks to all renders, trusted or not. As recommended in the docs, you should have a dedicated environment for sandboxes, different from the main one, but it's not really "enforced" nor natural to do.
* As a consequence, we store some state via `enableSandbox()`/`disableSandbox()` with try/finally patterns scattered across the codebase to support rendering sandboxed and non-sandboxed templates from a environment.
* When using one environment, a sandboxed template can `include` anything the loader can load, sees every application global, and inherits all extensions, this is a footgun (again, already not recommended in the docs).
* There are too maybe "knobs": global mode, `enableSandbox()`, `{% include(..., sandboxed: true) %}`, and `{% sandbox %}`.

The new `Twig\Sandbox\Sandbox` class renders untrusted templates through a dedicated, always-sandboxed environment crafted by the developer. Taht way, there is no state to toggle and nothing leaks between the main environment and the sandbox, in either direction.

Commits
-------

b762bc94b9 Make the sandbox a first-class citizen with a dedicated Sandbox class
2026-07-30 12:05:54 +02:00
Fabien Potencier b762bc94b9 Make the sandbox a first-class citizen with a dedicated Sandbox class 2026-07-30 12:05:47 +02:00
Fabien Potencier 096da67e7b Remove deprecated macro calls without parentheses 2026-07-28 16:39:05 +02:00
Fabien Potencier 9b42c9bd3d Merge branch '3.x' into 4.x
* 3.x:
  Deprecate macro calls without parentheses

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
2026-07-28 16:26:41 +02:00
Fabien Potencier 5bbbe0d8d6 feature #4877 Deprecate macro calls without parentheses (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate macro calls without parentheses

Commits
-------

ad305b414e Deprecate macro calls without parentheses
2026-07-28 16:24:59 +02:00
Fabien Potencier ad305b414e Deprecate macro calls without parentheses 2026-07-28 16:13:23 +02:00
Fabien Potencier 8bfb29b953 Remove deprecated code 2026-07-28 14:52:35 +02:00
Fabien Potencier 80df3b5f63 Merge branch '3.x' into 4.x
* 3.x:
  Rename macro variable AST nodes

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	src/ExpressionParser/Infix/DotExpressionParser.php
#	src/Node/Expression/Variable/TemplateVariable.php
#	src/Node/ImportNode.php
#	src/Parser.php
2026-07-28 14:47:56 +02:00
Fabien Potencier a2a4c1b4f2 feature #4876 Rename macro variable AST nodes (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Rename macro variable AST nodes

The current name are just wrong as these classes are only used in the context of macros. They were confusing.

Commits
-------

be36fee09e Rename macro variable AST nodes
2026-07-28 12:07:42 +02:00
Fabien Potencier be36fee09e Rename macro variable AST nodes 2026-07-28 11:53:50 +02:00
Fabien Potencier 2100129669 Remove deprecated code 2026-07-28 10:13:16 +02:00
Fabien Potencier d266b2df7f Merge branch '3.x' into 4.x
* 3.x:
  Clarify the security scope for untrusted templates
  Normalize destructuring assignment targets
  Deprecate duplicate macro definitions

# Conflicts:
#	CHANGELOG
#	doc/deprecated.rst
#	tests/ExpressionParserTest.php
2026-07-28 09:58:56 +02:00
Fabien Potencier ccc4a80ba7 documentation #4875 Clarify the security scope for untrusted templates (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Clarify the security scope for untrusted templates

Commits
-------

222a7f3f9a Clarify the security scope for untrusted templates
2026-07-28 09:51:25 +02:00
Fabien Potencier 222a7f3f9a Clarify the security scope for untrusted templates 2026-07-28 08:40:21 +02:00
Fabien Potencier 239cf25362 feature #4874 Normalize destructuring assignment targets (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Normalize destructuring assignment targets

Commits
-------

6ce5beb7c2 Normalize destructuring assignment targets
2026-07-27 18:57:15 +02:00
Fabien Potencier 6ce5beb7c2 Normalize destructuring assignment targets 2026-07-27 18:51:15 +02:00
Fabien Potencier 44f6f7e6c8 feature #4873 Deprecate duplicate macro definitions (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate duplicate macro definitions

Commits
-------

258089b8a6 Deprecate duplicate macro definitions
2026-07-27 12:45:09 +02:00
Fabien Potencier 258089b8a6 Deprecate duplicate macro definitions 2026-07-27 12:24:45 +02:00
Fabien Potencier 289f6a4a77 Fix merge conflict resolution 2026-07-26 07:53:49 +02:00
Fabien Potencier 19e6f46b90 Merge branch '3.x' into 4.x
* 3.x:
  Reuse assignment targets parsed for the for tag
  add shadowing example
  Update for.rst
  Fix IntlExtension ignoring explicit formats when a date formatter prototype is set
  bump Twig version metadata

# Conflicts:
#	CHANGELOG
#	doc/tags/for.rst
#	src/Environment.php
#	src/TokenParser/ForTokenParser.php
2026-07-26 07:52:24 +02:00
Fabien Potencier 293d05504b tidy #4872 Reuse assignment targets parsed for the for tag (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Reuse assignment targets parsed for the for tag

`ForTokenParser` rebuilds the loop targets returned by `parseAssignmentExpression()` into new `AssignContextVariable` instances, copying only the name and line number. But the parsed targets are already `AssignContextVariable` nodes with exactly those values, so the rebuild is a no-op left over from older Twig versions where for-targets were parsed as general expressions and needed normalizing.

Reusing the parsed nodes directly removes dead code, and makes the parser more robust: any metadata attached to the targets during parsing (now or in the future) is preserved instead of being silently dropped.

Commits
-------

9408f2a3f1 Reuse assignment targets parsed for the for tag
2026-07-25 18:00:28 +02:00
Fabien Potencier 9408f2a3f1 Reuse assignment targets parsed for the for tag 2026-07-25 17:48:54 +02:00
Fabien Potencier 7f94646a3b documentation #4862 Update for.rst (marilenaRM, Marilena Ruffelaere)
This PR was merged into the 3.x branch.

Discussion
----------

Update for.rst

Add context and explanation about loop.parent.

Commits
-------

02382585e9 add shadowing example
7234d51ec8 Update for.rst
2026-07-21 13:07:40 +02:00
Marilena Ruffelaere 02382585e9 add shadowing example 2026-07-20 18:57:40 +02:00
Fabien Potencier 66cb19fa98 bug #4867 Fix PHPStan errors on 4.x (fabpot)
This PR was merged into the 4.x branch.

Discussion
----------

Fix PHPStan errors on 4.x

Commits
-------

5e726bcce1 Fix PHPStan errors on 4.x
2026-07-19 18:22:03 +02:00
Fabien Potencier 5e726bcce1 Fix PHPStan errors on 4.x 2026-07-19 18:19:21 +02:00
Fabien Potencier 7d8248fb5f tidy #4866 ⚰️ Drop useless php comparisons (homersimpsons)
This PR was merged into the 4.x branch.

Discussion
----------

⚰️ Drop useless php comparisons

Commits
-------

f2e549a92b ⚰️ Drop useless php comparisons
2026-07-19 17:50:53 +02:00
Guillaume f2e549a92b ⚰️ Drop useless php comparisons 2026-07-18 18:06:34 +02:00
Marilena RUFFELAERE 7234d51ec8 Update for.rst
Add context and explanation about loop.parent
2026-07-17 15:42:51 +02:00
Fabien Potencier da8bd40700 bug #4859 Fix IntlExtension ignoring explicit formats when a date formatter prototype is set (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Fix IntlExtension ignoring explicit formats when a date formatter prototype is set

Closes #3845

Commits
-------

083b6dcabe Fix IntlExtension ignoring explicit formats when a date formatter prototype is set
2026-07-13 12:17:57 +02:00
Fabien Potencier 083b6dcabe Fix IntlExtension ignoring explicit formats when a date formatter prototype is set 2026-07-13 12:17:54 +02:00
Fabien Potencier ebd4d16d8a tidy #4861 bump Twig version metadata (xabbuh)
This PR was merged into the 3.x branch.

Discussion
----------

bump Twig version metadata

following #4852

Commits
-------

57905dab67 bump Twig version metadata
2026-07-13 12:14:31 +02:00
Christian Flothmann 57905dab67 bump Twig version metadata 2026-07-13 10:56:44 +02:00
Fabien Potencier d659593774 Merge branch '3.x' into 4.x
* 3.x:
  Document sandbox handling of magic __call() methods
  Add sandbox tests for methods routed through __call()

# Conflicts:
#	doc/sandbox.rst
#	tests/Extension/SandboxTest.php
2026-07-12 15:56:39 +02:00
Fabien Potencier bfbd962c5f tidy #4858 Document and test sandbox __call support (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Document and test sandbox __call support

Related to #1950

Commits
-------

29b66fd916 Document sandbox handling of magic __call() methods
72da20aeb7 Add sandbox tests for methods routed through __call()
2026-07-12 15:54:43 +02:00
Fabien Potencier 29b66fd916 Document sandbox handling of magic __call() methods 2026-07-12 15:45:50 +02:00
Fabien Potencier 72da20aeb7 Add sandbox tests for methods routed through __call() 2026-07-12 15:45:50 +02:00
Fabien Potencier 075dd703d0 Merge branch '3.x' into 4.x
* 3.x:
  Disable the fabbot test-case return type check
2026-07-12 15:39:22 +02:00