mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 20:36:33 +00:00
fixed the defined test when used on a constant, a map, or a sequence
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
* 1.23.4 (2016-XX-XX)
|
* 1.23.4 (2016-XX-XX)
|
||||||
|
|
||||||
|
* fixed the defined test when used on a constant, a map, or a sequence
|
||||||
* undeprecated _self (should only be used to get the template name, not the template instance)
|
* undeprecated _self (should only be used to get the template name, not the template instance)
|
||||||
* fixed parsing on PHP7
|
* fixed parsing on PHP7
|
||||||
|
|
||||||
|
|||||||
@@ -25,17 +25,19 @@ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
|
|||||||
{
|
{
|
||||||
public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
|
public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct($node, $name, $arguments, $lineno);
|
|
||||||
|
|
||||||
if ($node instanceof Twig_Node_Expression_Name) {
|
if ($node instanceof Twig_Node_Expression_Name) {
|
||||||
$node->setAttribute('is_defined_test', true);
|
$node->setAttribute('is_defined_test', true);
|
||||||
} elseif ($node instanceof Twig_Node_Expression_GetAttr) {
|
} elseif ($node instanceof Twig_Node_Expression_GetAttr) {
|
||||||
$node->setAttribute('is_defined_test', true);
|
$node->setAttribute('is_defined_test', true);
|
||||||
|
|
||||||
$this->changeIgnoreStrictCheck($node);
|
$this->changeIgnoreStrictCheck($node);
|
||||||
|
} elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) {
|
||||||
|
$node = new Twig_Node_Expression_Constant(true, $node->getLine());
|
||||||
} else {
|
} else {
|
||||||
throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getLine());
|
throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parent::__construct($node, $name, $arguments, $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
|
protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
|
||||||
|
|||||||
@@ -26,6 +26,13 @@
|
|||||||
{{ object.self.foo is defined ? 'ok' : 'ko' }}
|
{{ object.self.foo is defined ? 'ok' : 'ko' }}
|
||||||
{{ object.self.undefinedMethod is defined ? 'ko' : 'ok' }}
|
{{ object.self.undefinedMethod is defined ? 'ko' : 'ok' }}
|
||||||
{{ object.undefinedMethod.self is defined ? 'ko' : 'ok' }}
|
{{ object.undefinedMethod.self is defined ? 'ko' : 'ok' }}
|
||||||
|
{{ 0 is defined ? 'ok' : 'ko' }}
|
||||||
|
{{ "foo" is defined ? 'ok' : 'ko' }}
|
||||||
|
{{ true is defined ? 'ok' : 'ko' }}
|
||||||
|
{{ false is defined ? 'ok' : 'ko' }}
|
||||||
|
{{ null is defined ? 'ok' : 'ko' }}
|
||||||
|
{{ [1, 2] is defined ? 'ok' : 'ko' }}
|
||||||
|
{{ { foo: "bar" } is defined ? 'ok' : 'ko' }}
|
||||||
--DATA--
|
--DATA--
|
||||||
return array(
|
return array(
|
||||||
'definedVar' => 'defined',
|
'definedVar' => 'defined',
|
||||||
@@ -65,6 +72,13 @@ ok
|
|||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
--DATA--
|
--DATA--
|
||||||
return array(
|
return array(
|
||||||
'definedVar' => 'defined',
|
'definedVar' => 'defined',
|
||||||
@@ -106,3 +120,10 @@ ok
|
|||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
|||||||
Reference in New Issue
Block a user