mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-10 01:16:52 +00:00
Merge branch '1.x' into 2.x
* 1.x: fixed regression in NodeTraverser
This commit is contained in:
@@ -224,7 +224,7 @@
|
||||
|
||||
* 1.40.1 (2019-XX-XX)
|
||||
|
||||
* n/a
|
||||
* fixed regression in NodeTraverser
|
||||
|
||||
* 1.40.0 (2019-04-28)
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@ final class NodeTraverser
|
||||
$node = $visitor->enterNode($node, $this->env);
|
||||
|
||||
foreach ($node as $k => $n) {
|
||||
if (null === $n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false !== ($m = $this->traverseForVisitor($visitor, $n)) && null !== $m) {
|
||||
if ($m !== $n) {
|
||||
$node->setNode($k, $m);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Twig\NodeTraverser;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Environment;
|
||||
use Twig\NodeVisitor\NodeVisitorInterface;
|
||||
|
||||
class Twig_Tests_NodeTraverserTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testNodeIsNullWhenTraversing()
|
||||
{
|
||||
$env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock());
|
||||
$traverser = new NodeTraverser($env, [new IdentityVisitor()]);
|
||||
$n = new Node([new Node([]), null, new Node([])]);
|
||||
$this->assertCount(3, $traverser->traverse($n));
|
||||
}
|
||||
}
|
||||
|
||||
class IdentityVisitor implements NodeVisitorInterface
|
||||
{
|
||||
public function enterNode(\Twig_NodeInterface $node, Environment $env)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function leaveNode(\Twig_NodeInterface $node, Environment $env)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user