From: nikic <+@ni-po.com> Date: Tue, 3 May 2011 16:56:57 +0000 (+0200) Subject: Fix regression in defined test for GetAttr. Fixes #319 X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b0a94baebd5e3b9c41babd29fb093eb6a327a2e7;p=web%2Fkonrad%2Ftwig.git Fix regression in defined test for GetAttr. Fixes #319 --- diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index 2a69e8c..3025209 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -33,8 +33,9 @@ class Twig_Node_Expression_Test extends Twig_Node_Expression } elseif ($this->getNode('node') instanceof Twig_Node_Expression_GetAttr) { $this->getNode('node')->setAttribute('is_defined_test', true); $compiler - ->raw('null !== ') + ->raw('(null !== ') ->subcompile($this->getNode('node')) + ->raw(')') ; } else { throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine()); diff --git a/test/Twig/Tests/Fixtures/tests/defined.test b/test/Twig/Tests/Fixtures/tests/defined.test index b6119c0..2a8ae01 100644 --- a/test/Twig/Tests/Fixtures/tests/defined.test +++ b/test/Twig/Tests/Fixtures/tests/defined.test @@ -6,6 +6,7 @@ {{ foobar is not defined ? 'ok' : 'ko' }} {{ zero is defined ? 'ok' : 'ko' }} {{ nested.foo is defined ? 'ok' : 'ko' }} +{{ nested.foo is not defined ? 'ok' : 'ko' }} {{ nested.bar is not defined ? 'ok' : 'ko' }} {{ nested.zero is defined ? 'ok' : 'ko' }} --DATA-- @@ -16,5 +17,6 @@ ok ok ok ok +ko ok ok