mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
fixed regression
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
* 2.4.8 (2018-XX-XX)
|
* 2.4.8 (2018-XX-XX)
|
||||||
|
|
||||||
* n/a
|
* fixed a regression when using the "default" filter or the "defined" test on non-existing arrays
|
||||||
|
|
||||||
* 2.4.7 (2018-03-20)
|
* 2.4.7 (2018-03-20)
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
|||||||
$nodes['arguments'] = $arguments;
|
$nodes['arguments'] = $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($nodes, array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno);
|
parent::__construct($nodes, array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'optimizable' => true), $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Twig_Compiler $compiler)
|
||||||
@@ -27,7 +27,8 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
|||||||
|
|
||||||
// optimize array calls
|
// optimize array calls
|
||||||
if (
|
if (
|
||||||
(!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check'))
|
$this->getAttribute('optimizable')
|
||||||
|
&& (!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check'))
|
||||||
&& !$this->getAttribute('is_defined_test')
|
&& !$this->getAttribute('is_defined_test')
|
||||||
&& Twig_Template::ARRAY_CALL === $this->getAttribute('type')
|
&& Twig_Template::ARRAY_CALL === $this->getAttribute('type')
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
|
|||||||
|
|
||||||
private function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
|
private function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
|
||||||
{
|
{
|
||||||
|
$node->setAttribute('optimizable', false);
|
||||||
$node->setAttribute('ignore_strict_check', true);
|
$node->setAttribute('ignore_strict_check', true);
|
||||||
|
|
||||||
if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
|
if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
|
||||||
|
|||||||
@@ -40,8 +40,13 @@ Twig supports array notation
|
|||||||
|
|
||||||
{# ArrayAccess #}
|
{# ArrayAccess #}
|
||||||
{{ array_access['a'] }}
|
{{ array_access['a'] }}
|
||||||
|
|
||||||
|
{# array that does not exist #}
|
||||||
|
{{ does_not_exist[0]|default('ok') }}
|
||||||
|
{{ does_not_exist[0].does_not_exist_either|default('ok') }}
|
||||||
|
{{ does_not_exist[0]['does_not_exist_either']|default('ok') }}
|
||||||
--DATA--
|
--DATA--
|
||||||
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'array_access' => new ArrayObject(array('a' => 'b')))
|
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'array_access' => new ArrayObject(array('a' => 'b')))
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
1,2
|
1,2
|
||||||
foo,bar
|
foo,bar
|
||||||
@@ -64,6 +69,10 @@ FOO,BAR,
|
|||||||
a,b,c,d
|
a,b,c,d
|
||||||
|
|
||||||
b
|
b
|
||||||
|
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
--DATA--
|
--DATA--
|
||||||
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'array_access' => new ArrayObject(array('a' => 'b')))
|
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'array_access' => new ArrayObject(array('a' => 'b')))
|
||||||
--CONFIG--
|
--CONFIG--
|
||||||
@@ -90,3 +99,7 @@ FOO,BAR,
|
|||||||
a,b,c,d
|
a,b,c,d
|
||||||
|
|
||||||
b
|
b
|
||||||
|
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Array access:
|
|||||||
{{ nested.nullVar |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ nested.nullVar |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
{{ nested.undefinedVar |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ nested.undefinedVar |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
{{ nested['undefinedVar'] |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ nested['undefinedVar'] |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
|
{{ undefined['undefined'] |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
{{ undefinedVar.foo |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ undefinedVar.foo |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
Plain values:
|
Plain values:
|
||||||
{{ 'defined' |default('default') is same as('default') ? 'ko' : 'ok' }}
|
{{ 'defined' |default('default') is same as('default') ? 'ko' : 'ok' }}
|
||||||
@@ -35,6 +36,8 @@ Deep nested:
|
|||||||
{{ nested.undefinedVar.foo.bar |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ nested.undefinedVar.foo.bar |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
{{ nested.definedArray.0 |default('default') is same as('default') ? 'ko' : 'ok' }}
|
{{ nested.definedArray.0 |default('default') is same as('default') ? 'ko' : 'ok' }}
|
||||||
{{ nested['definedArray'][0] |default('default') is same as('default') ? 'ko' : 'ok' }}
|
{{ nested['definedArray'][0] |default('default') is same as('default') ? 'ko' : 'ok' }}
|
||||||
|
{{ nested['undefinedVar'][0] |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
|
{{ undefined['undefined'][0] |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
{{ object.self.foo |default('default') is same as('default') ? 'ko' : 'ok' }}
|
{{ object.self.foo |default('default') is same as('default') ? 'ko' : 'ok' }}
|
||||||
{{ object.self.undefinedMethod |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ object.self.undefinedMethod |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
{{ object.undefinedMethod.self |default('default') is same as('default') ? 'ok' : 'ko' }}
|
{{ object.undefinedMethod.self |default('default') is same as('default') ? 'ok' : 'ko' }}
|
||||||
@@ -71,6 +74,7 @@ ok
|
|||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
|
ok
|
||||||
Plain values:
|
Plain values:
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
@@ -93,6 +97,8 @@ ok
|
|||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
--DATA--
|
--DATA--
|
||||||
return array(
|
return array(
|
||||||
'definedVar' => 'defined',
|
'definedVar' => 'defined',
|
||||||
@@ -126,6 +132,7 @@ ok
|
|||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
|
ok
|
||||||
Plain values:
|
Plain values:
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
@@ -148,3 +155,5 @@ ok
|
|||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
ok
|
ok
|
||||||
|
ok
|
||||||
|
ok
|
||||||
|
|||||||
Reference in New Issue
Block a user