fixed edge case in the method cache for Twig attributes

This commit is contained in:
Fabien Potencier
2017-04-18 16:40:36 -06:00
parent 530be06a5a
commit 413be4167b
3 changed files with 33 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 1.33.2 (2017-XX-XX)
* n/a
* fixed edge case in the method cache for Twig attributes
* 1.33.1 (2017-04-18)
+8 -5
View File
@@ -627,11 +627,14 @@ abstract class Twig_Template implements Twig_TemplateInterface
continue;
}
if (!isset($cache[$name])) {
$cache[$name] = $method;
}
if (!isset($cache[$lcName])) {
$cache[$lcName] = $method;
// skip get() and is() methods (in which case, $name is empty)
if ($name) {
if (!isset($cache[$name])) {
$cache[$name] = $method;
}
if (!isset($cache[$lcName])) {
$cache[$lcName] = $method;
}
}
}
self::$cache[$class] = $cache;
+24
View File
@@ -424,6 +424,19 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
return $tests;
}
/**
* @expectedException Twig_Error_Runtime
*/
public function testGetIsMethods()
{
$getIsObject = new Twig_TemplateGetIsMethods();
$template = new Twig_TemplateTest(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('strict_variables' => true)));
// first time should not create a cache for "get"
$this->assertNull($template->getAttribute($getIsObject, 'get'));
// 0 should be in the method cache now, so this should fail
$this->assertNull($template->getAttribute($getIsObject, 0));
}
}
class Twig_TemplateTest extends Twig_Template
@@ -669,6 +682,17 @@ class Twig_TemplateMethodObject
}
}
class Twig_TemplateGetIsMethods
{
public function get()
{
}
public function is()
{
}
}
class Twig_TemplateMethodAndPropObject
{
private $a = 'a_prop';