Skip to content

Commit 42c5bfd

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: don't use deprecated and internal Twig functions [Notifier][Clickatell] Fixed minor typo add missing translation [Messenger] Add missing Redis cleanup in tests Make sure Serializer::denormalize have show what exception it throws
2 parents c514076 + 4ced0e9 commit 42c5bfd

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Node/SearchAndRenderBlockNode.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Node;
1313

1414
use Twig\Compiler;
15+
use Twig\Extension\CoreExtension;
1516
use Twig\Node\Expression\ArrayExpression;
1617
use Twig\Node\Expression\ConstantExpression;
1718
use Twig\Node\Expression\FunctionExpression;
@@ -50,7 +51,7 @@ public function compile(Compiler $compiler): void
5051
$labelIsExpression = false;
5152

5253
// Only insert the label into the array if it is not empty
53-
if (!twig_test_empty($label->getAttribute('value'))) {
54+
if (null !== $label->getAttribute('value') && false !== $label->getAttribute('value') && '' !== (string) $label->getAttribute('value')) {
5455
$originalVariables = $variables;
5556
$variables = new ArrayExpression([], $lineno);
5657
$labelKey = new ConstantExpression('label', $lineno);
@@ -97,7 +98,12 @@ public function compile(Compiler $compiler): void
9798

9899
// Check at runtime whether the label is empty.
99100
// If not, add it to the array at runtime.
100-
$compiler->raw('(twig_test_empty($_label_ = ');
101+
if (method_exists(CoreExtension::class, 'testEmpty')) {
102+
$compiler->raw('(CoreExtension::testEmpty($_label_ = ');
103+
} else {
104+
$compiler->raw('(twig_test_empty($_label_ = ');
105+
}
106+
101107
$compiler->subcompile($label);
102108
$compiler->raw(') ? [] : ["label" => $_label_])');
103109
}

Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
1616
use Twig\Compiler;
1717
use Twig\Environment;
18+
use Twig\Extension\CoreExtension;
1819
use Twig\Loader\LoaderInterface;
1920
use Twig\Node\Expression\ArrayExpression;
2021
use Twig\Node\Expression\ConditionalExpression;
@@ -226,8 +227,9 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
226227
// https://github.com/symfony/symfony/issues/5029
227228
$this->assertEquals(
228229
sprintf(
229-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
230-
$this->getVariableGetter('form')
230+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (%s($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
231+
$this->getVariableGetter('form'),
232+
method_exists(CoreExtension::class, 'testEmpty') ? 'CoreExtension::testEmpty' : 'twig_test_empty'
231233
),
232234
trim($compiler->compile($node)->getSource())
233235
);
@@ -263,8 +265,9 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
263265
// https://github.com/symfony/symfony/issues/5029
264266
$this->assertEquals(
265267
sprintf(
266-
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
267-
$this->getVariableGetter('form')
268+
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (%s($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
269+
$this->getVariableGetter('form'),
270+
method_exists(CoreExtension::class, 'testEmpty') ? 'CoreExtension::testEmpty' : 'twig_test_empty'
268271
),
269272
trim($compiler->compile($node)->getSource())
270273
);

0 commit comments

Comments
 (0)