Merge remote branch 'nikic/fixIncorrectGetAttrDefinedSoftCheck'

* nikic/fixIncorrectGetAttrDefinedSoftCheck:
  Use a type strict null check for GetAttr defined tests. Fixes #305
This commit is contained in:
Fabien Potencier
2011-04-28 16:20:15 +02:00
2 changed files with 7 additions and 2 deletions
+4 -1
View File
@@ -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());
}
+3 -1
View File
@@ -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