mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
fixed edge case in the method cache for Twig attributes
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user