From 413be4167b09fbc5212e1544f64d1d34f114ff0e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 18 Apr 2017 16:40:36 -0600 Subject: [PATCH 1/3] fixed edge case in the method cache for Twig attributes --- CHANGELOG | 2 +- lib/Twig/Template.php | 13 ++++++++----- test/Twig/Tests/TemplateTest.php | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e8009702b..b335d7f3e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index f1855f117..c631befe2 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -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; diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index faa68c6c0..4da2d5750 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -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'; From dd6ca96227917e1e85b41c7c3cc6507b411e0927 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 20 Apr 2017 11:39:48 -0600 Subject: [PATCH 2/3] prepared the 1.33.2 release --- CHANGELOG | 2 +- ext/twig/php_twig.h | 2 +- lib/Twig/Environment.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b335d7f3e..fd24dfeae 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -* 1.33.2 (2017-XX-XX) +* 1.33.2 (2017-04-20) * fixed edge case in the method cache for Twig attributes diff --git a/ext/twig/php_twig.h b/ext/twig/php_twig.h index a8cf6c4b0..0a12ea575 100644 --- a/ext/twig/php_twig.h +++ b/ext/twig/php_twig.h @@ -15,7 +15,7 @@ #ifndef PHP_TWIG_H #define PHP_TWIG_H -#define PHP_TWIG_VERSION "1.33.2-DEV" +#define PHP_TWIG_VERSION "1.33.2" #include "php.h" diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 8c7783c79..ae07a512b 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -21,7 +21,7 @@ class Twig_Environment const MAJOR_VERSION = 1; const MINOR_VERSION = 33; const RELEASE_VERSION = 1; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; protected $charset; protected $loader; From ef680be80ef9e4f785f3f51c86bfaca8d991e801 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 20 Apr 2017 11:41:13 -0600 Subject: [PATCH 3/3] bumped version to 1.33.3-DEV --- CHANGELOG | 4 ++++ ext/twig/php_twig.h | 2 +- lib/Twig/Environment.php | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fd24dfeae..752a12724 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +* 1.33.3 (2017-XX-XX) + + * n/a + * 1.33.2 (2017-04-20) * fixed edge case in the method cache for Twig attributes diff --git a/ext/twig/php_twig.h b/ext/twig/php_twig.h index 0a12ea575..656cbfba8 100644 --- a/ext/twig/php_twig.h +++ b/ext/twig/php_twig.h @@ -15,7 +15,7 @@ #ifndef PHP_TWIG_H #define PHP_TWIG_H -#define PHP_TWIG_VERSION "1.33.2" +#define PHP_TWIG_VERSION "1.33.3-DEV" #include "php.h" diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index ae07a512b..51ffc53fe 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -16,12 +16,12 @@ */ class Twig_Environment { - const VERSION = '1.33.2'; - const VERSION_ID = 13302; + const VERSION = '1.33.3'; + const VERSION_ID = 13303; const MAJOR_VERSION = 1; const MINOR_VERSION = 33; - const RELEASE_VERSION = 1; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 3; + const EXTRA_VERSION = 'DEV'; protected $charset; protected $loader;