From b0a94baebd5e3b9c41babd29fb093eb6a327a2e7 Mon Sep 17 00:00:00 2001 From: nikic <+@ni-po.com> Date: Tue, 3 May 2011 18:56:57 +0200 Subject: [PATCH] Fix regression in defined test for GetAttr. Fixes #319 --- lib/Twig/Node/Expression/Test.php | 3 ++- test/Twig/Tests/Fixtures/tests/defined.test | 2 ++ 2 files changed, 4 insertions(+), 1 deletions(-) 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 -- 1.7.2.5