From: nikic <+@ni-po.com> Date: Thu, 28 Apr 2011 11:17:49 +0000 (+0200) Subject: Use a type strict null check for GetAttr defined tests. Fixes #305 X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=17af31b5b42c382ed7ed2e1f1d618b450b556fb7;p=konrad%2Ftwig.git Use a type strict null check for GetAttr defined tests. Fixes #305 --- diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index 4995bc7..2a69e8c 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -32,7 +32,10 @@ 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->subcompile($this->getNode('node')); + $compiler + ->raw('null !== ') + ->subcompile($this->getNode('node')) + ; } 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 a401b5e..e4159fd 100644 --- a/test/Twig/Tests/Fixtures/tests/defined.test +++ b/test/Twig/Tests/Fixtures/tests/defined.test @@ -6,11 +6,13 @@ {{ foobar is not defined ? 'ok' : 'ko' }} {{ nested.foo is defined ? 'ok' : 'ko' }} {{ nested.bar is not defined ? 'ok' : 'ko' }} +{{ nested.zero is defined ? 'ok' : 'ko' }} --DATA-- -return array('foo' => 'bar', 'bar' => null, 'nested' => array('foo' => 'foo')); +return array('foo' => 'bar', 'bar' => null, 'nested' => array('foo' => 'foo', 'zero' => 0)); --EXPECT-- ok ok ok ok ok +ok