Fix the default filter fallback reusing a null-safe temporary variable

This commit is contained in:
Lazizbek Ergashev
2026-09-01 14:06:43 +05:00
parent c32656815b
commit 86c830ef45
3 changed files with 23 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
# 3.29.0 (2026-XX-XX)
* Fix the `default` filter fallback emitting an undefined variable warning when it uses the null-safe operator
* Fix the `matches` operator silently treating PCRE execution errors as non-matches
* Add the `HtmlExtension::htmlAttrValue()` method to resolve a single HTML attribute value the way the `html_attr` function renders it
* Fix `html_attr` JSON encoding a `Stringable` value in a `data-*` attribute instead of using its string representation
+1 -1
View File
@@ -55,7 +55,7 @@ class DefaultFilter extends FilterExpression
if ('default' === $name && ($node instanceof ContextVariable || $node instanceof GetAttrExpression)) {
$test = new DefinedTest(clone $node, new TwigTest('defined', null, ['always_allowed_in_sandbox' => true]), new EmptyNode(), $node->getTemplateLine());
$false = \count($arguments) ? $arguments->getNode('0') : new ConstantExpression('', $node->getTemplateLine());
$false = \count($arguments) ? clone $arguments->getNode('0') : new ConstantExpression('', $node->getTemplateLine());
$node = new ConditionalTernary($test, $default, $false, $node->getTemplateLine());
} else {
+21
View File
@@ -445,6 +445,27 @@ class ExpressionParserTest extends TestCase
['foo' => (object) ['bar' => (object) ['baz' => null]]],
'',
],
// default filter fallback
[
'{{ foo?.bar|default(foo?.baz) }}',
['foo' => null],
'',
],
[
'{{ foo?.bar|default(foo?.baz.qux) }}',
['foo' => null],
'',
],
[
'{{ foo?.bar|default(foo?.baz) }}',
['foo' => (object) ['bar' => null, 'baz' => 'qux']],
'qux',
],
[
'{{ foo?.bar|default(foo?.baz) }}',
['foo' => (object) ['bar' => 'corge', 'baz' => 'qux']],
'corge',
],
];
}