From b22ce0eb070e41f7cba65d78fe216de29726459c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 23 Nov 2016 10:41:40 -0800 Subject: [PATCH 1/5] prepared the 1.28.2 release --- CHANGELOG | 2 +- ext/twig/php_twig.h | 2 +- lib/Twig/Environment.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a1b6a3b4a..fab1bfbc7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -* 1.28.2 (2016-XX-XX) +* 1.28.2 (2016-11-23) * fixed precedence between getFoo() and isFoo() in Twig_Template::getAttribute() * improved a deprecation message diff --git a/ext/twig/php_twig.h b/ext/twig/php_twig.h index b5eab0b5b..f4f8e0629 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.28.2-DEV" +#define PHP_TWIG_VERSION "1.28.2" #include "php.h" diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index e55e7d6d3..7153790e9 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -16,12 +16,12 @@ */ class Twig_Environment { - const VERSION = '1.28.2-DEV'; + const VERSION = '1.28.2'; const VERSION_ID = 12802; const MAJOR_VERSION = 1; const MINOR_VERSION = 28; const RELEASE_VERSION = 2; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; protected $charset; protected $loader; From 2436915b4632ddb27dcffe99e4029cf4759ea99f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 23 Nov 2016 10:45:18 -0800 Subject: [PATCH 2/5] bumped version to 1.28.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 fab1bfbc7..420a275e0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +* 1.28.3 (2016-XX-XX) + + * n/a + * 1.28.2 (2016-11-23) * fixed precedence between getFoo() and isFoo() in Twig_Template::getAttribute() diff --git a/ext/twig/php_twig.h b/ext/twig/php_twig.h index f4f8e0629..9f1e8eb72 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.28.2" +#define PHP_TWIG_VERSION "1.28.3-DEV" #include "php.h" diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 7153790e9..d355c1dfa 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -16,12 +16,12 @@ */ class Twig_Environment { - const VERSION = '1.28.2'; - const VERSION_ID = 12802; + const VERSION = '1.28.3'; + const VERSION_ID = 12803; const MAJOR_VERSION = 1; const MINOR_VERSION = 28; - const RELEASE_VERSION = 2; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 3; + const EXTRA_VERSION = 'DEV'; protected $charset; protected $loader; From 6668d475d68425c1f6b720e9f229ec102b4179e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 19 Nov 2016 11:35:44 -0800 Subject: [PATCH 3/5] deprecated support for mbstring.func_overload != 0 --- CHANGELOG | 4 ++-- composer.json | 2 +- ext/twig/php_twig.h | 2 +- lib/Twig/Compiler.php | 2 ++ lib/Twig/Environment.php | 8 ++++---- lib/Twig/Lexer.php | 4 ++++ 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 420a275e0..17797c76d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ -* 1.28.3 (2016-XX-XX) +* 1.29.0 (2016-XX-XX) - * n/a + * deprecated support for mbstring.func_overload != 0 * 1.28.2 (2016-11-23) diff --git a/composer.json b/composer.json index c0ff2e284..5bf8a436c 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.28-dev" + "dev-master": "1.29-dev" } } } diff --git a/ext/twig/php_twig.h b/ext/twig/php_twig.h index 9f1e8eb72..8ae3ffde8 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.28.3-DEV" +#define PHP_TWIG_VERSION "1.29.0-DEV" #include "php.h" diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index 5e96ac35f..7ab8feff7 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -216,6 +216,8 @@ class Twig_Compiler implements Twig_CompilerInterface // mb_substr_count() replaces substr_count() // but they have different signatures! if (((int) ini_get('mbstring.func_overload')) & 2) { + @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED); + // this is much slower than the "right" version $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); } else { diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index d355c1dfa..0544de1e2 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -16,11 +16,11 @@ */ class Twig_Environment { - const VERSION = '1.28.3'; - const VERSION_ID = 12803; + const VERSION = '1.29.0-DEV'; + const VERSION_ID = 12900; const MAJOR_VERSION = 1; - const MINOR_VERSION = 28; - const RELEASE_VERSION = 3; + const MINOR_VERSION = 20; + const RELEASE_VERSION = 0; const EXTRA_VERSION = 'DEV'; protected $charset; diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 0e7019f56..97b4a5c68 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -85,6 +85,10 @@ class Twig_Lexer implements Twig_LexerInterface $source = $code; } + if (((int) ini_get('mbstring.func_overload')) & 2) { + @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED); + } + if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); From 75d474a22399086ce9de4667e50f7fb230d03358 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Fri, 25 Nov 2016 19:12:56 +0100 Subject: [PATCH 4/5] Deprecate usage of undefined blocks --- lib/Twig/Template.php | 14 ++++++---- .../recursive_block_with_inheritance.test | 2 +- .../functions/undefined_block.legacy.test | 12 ++++++++ test/Twig/Tests/TemplateTest.php | 28 ++++++++++++++++--- 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 test/Twig/Tests/LegacyFixtures/functions/undefined_block.legacy.test diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 54f6b0dcd..bedc7e9ca 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -197,12 +197,16 @@ abstract class Twig_Template implements Twig_TemplateInterface $block = null; } - if (null !== $template) { - // avoid RCEs when sandbox is enabled - if (!$template instanceof self) { - throw new LogicException('A block must be a method on a Twig_Template instance.'); - } + // avoid RCEs when sandbox is enabled + if (null !== $template && !$template instanceof self) { + throw new LogicException('A block must be a method on a Twig_Template instance.'); + } + if (!$this->hasBlock($name, $context, $blocks)) { + @trigger_error(sprintf('Displaying undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0.', $name, $this->getTemplateName()), E_USER_DEPRECATED); + } + + if (null !== $template) { try { $template->$block($context, $blocks); } catch (Twig_Error $e) { diff --git a/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test b/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test index f39712da8..bf0556d24 100644 --- a/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test +++ b/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test @@ -12,7 +12,7 @@ {% block list %}
    {{ block('children') }}
{% endblock %} {% block children %}{% set currentItem = item %}{% for item in currentItem %}{{ block('item') }}{% endfor %}{% set item = currentItem %}{% endblock %} {% block item %}
  • {% if item is not iterable %}{{ block('label') }}{% else %}{{ block('list') }}{% endif %}
  • {% endblock %} -{% block label %}{{ item }}{{ block('unknown') }}{% endblock %} +{% block label %}{{ item }}{% endblock %} --TEMPLATE(base.twig)-- {{ block('list') }} --DATA-- diff --git a/test/Twig/Tests/LegacyFixtures/functions/undefined_block.legacy.test b/test/Twig/Tests/LegacyFixtures/functions/undefined_block.legacy.test new file mode 100644 index 000000000..62e24f0f4 --- /dev/null +++ b/test/Twig/Tests/LegacyFixtures/functions/undefined_block.legacy.test @@ -0,0 +1,12 @@ +--TEST-- +"block" function with undefined block +--TEMPLATE-- +{% extends "base.twig" %} +{% block foo %}{{ parent() }}{{ block('unknown') }}{{ block('bar') }}{% endblock %} +--TEMPLATE(base.twig)-- +{% block foo %}Foo{% endblock %} +{% block bar %}Bar{% endblock %} +--DATA-- +return array() +--EXPECT-- +FooBarBar diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 610b8c6c1..821e2c7a8 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -214,15 +214,17 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty')); $this->assertSame('', $template->getAttribute($template1, 'empty')); + $blocks = array('name' => array($template1, 'block_name')); + // trigger some deprecation notice messages to check them with @expectedDeprecation - $template->getAttribute($template, 'renderBlock', array('name', array())); - $template->getAttribute($template, 'displayBlock', array('name', array())); + $template->getAttribute($template, 'renderBlock', array('name', array(), $blocks)); + $template->getAttribute($template, 'displayBlock', array('name', array(), $blocks)); $template->getAttribute($template, 'hasBlock', array('name', array())); $template->getAttribute($template, 'render', array(array())); $template->getAttribute($template, 'display', array(array())); - $template->getAttribute($template1, 'renderBlock', array('name', array())); - $template->getAttribute($template1, 'displayBlock', array('name', array())); + $template->getAttribute($template1, 'renderBlock', array('name', array(), $blocks)); + $template->getAttribute($template1, 'displayBlock', array('name', array(), $blocks)); $template->getAttribute($template1, 'hasBlock', array('name', array())); $template->getAttribute($template1, 'render', array(array())); $template->getAttribute($template1, 'display', array(array())); @@ -233,6 +235,20 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', array(), Twig_Template::METHOD_CALL, true)); } + /** + * @group legacy + * @expectedDeprecation Displaying undefined block "unknown" in template "index.twig" is deprecated since version 1.29 and will throw an exception in 2.0. + * @expectedDeprecation Displaying undefined block "unknown" in template "index.twig" is deprecated since version 1.29 and will throw an exception in 2.0. + */ + public function testRenderBlockWithUndefinedBlock() + { + $twig = new Twig_Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + + $template = new Twig_TemplateTest($twig, false, 'index.twig'); + $template->renderBlock('unknown', array()); + $template->displayBlock('unknown', array()); + } + /** * @dataProvider getTestsDependingOnExtensionAvailability */ @@ -534,6 +550,10 @@ class Twig_TemplateTest extends Twig_Template return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); } } + + public function block_name($context, array $blocks = array()) + { + } } class Twig_TemplateArrayAccessObject implements ArrayAccess From ae9b503b17419102dbec3da4a583cf02c3ecf366 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Dec 2016 09:53:08 +0100 Subject: [PATCH 5/5] updated CHANGELOG --- CHANGELOG | 1 + lib/Twig/Template.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 17797c76d..b134af116 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.29.0 (2016-XX-XX) + * deprecated silent display of undefined blocks * deprecated support for mbstring.func_overload != 0 * 1.28.2 (2016-11-23) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index bedc7e9ca..f6b21fa1d 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -203,7 +203,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } if (!$this->hasBlock($name, $context, $blocks)) { - @trigger_error(sprintf('Displaying undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0.', $name, $this->getTemplateName()), E_USER_DEPRECATED); + @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0.', $name, $this->getTemplateName()), E_USER_DEPRECATED); } if (null !== $template) {