mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Merge remote branch 'nikic/fixIncorrectGetAttrDefinedSoftCheck'
* nikic/fixIncorrectGetAttrDefinedSoftCheck: Use a type strict null check for GetAttr defined tests. Fixes #305
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user