From ddfd70a7261459d2c260edaa348d418ed779aad4 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 28 Oct 2014 12:11:11 +0000 Subject: [PATCH] Issue #2363741 by joelpittet: Upgrade Twig to 1.16.* from 1.15.*. --- composer.json | 2 +- composer.lock | 14 +- core/vendor/composer/installed.json | 118 ++++++------ core/vendor/twig/twig/.travis.yml | 1 + core/vendor/twig/twig/CHANGELOG | 30 ++- core/vendor/twig/twig/composer.json | 2 +- core/vendor/twig/twig/doc/api.rst | 37 +--- core/vendor/twig/twig/doc/deprecated.rst | 10 +- core/vendor/twig/twig/doc/filters/batch.rst | 2 +- .../twig/doc/filters/convert_encoding.rst | 2 +- core/vendor/twig/twig/doc/filters/first.rst | 2 +- .../twig/twig/doc/filters/json_encode.rst | 2 +- core/vendor/twig/twig/doc/filters/last.rst | 2 +- core/vendor/twig/twig/doc/filters/length.rst | 2 +- core/vendor/twig/twig/doc/filters/merge.rst | 6 + core/vendor/twig/twig/doc/filters/nl2br.rst | 2 +- .../twig/twig/doc/filters/number_format.rst | 2 +- core/vendor/twig/twig/doc/filters/raw.rst | 24 +++ core/vendor/twig/twig/doc/filters/slice.rst | 5 +- core/vendor/twig/twig/doc/filters/split.rst | 18 +- core/vendor/twig/twig/doc/filters/trim.rst | 2 +- .../twig/twig/doc/filters/url_encode.rst | 10 +- core/vendor/twig/twig/doc/functions/date.rst | 4 +- core/vendor/twig/twig/doc/functions/dump.rst | 2 +- .../twig/twig/doc/functions/include.rst | 2 +- core/vendor/twig/twig/doc/functions/max.rst | 5 +- core/vendor/twig/twig/doc/functions/min.rst | 5 +- .../vendor/twig/twig/doc/functions/random.rst | 2 +- .../vendor/twig/twig/doc/functions/source.rst | 2 +- .../doc/functions/template_from_string.rst | 2 +- core/vendor/twig/twig/doc/index.rst | 4 +- core/vendor/twig/twig/doc/installation.rst | 91 +++++---- core/vendor/twig/twig/doc/internals.rst | 2 +- core/vendor/twig/twig/doc/intro.rst | 10 +- core/vendor/twig/twig/doc/recipes.rst | 2 +- core/vendor/twig/twig/doc/tags/autoescape.rst | 12 ++ core/vendor/twig/twig/doc/tags/do.rst | 2 +- core/vendor/twig/twig/doc/tags/extends.rst | 4 +- core/vendor/twig/twig/doc/tags/if.rst | 17 ++ core/vendor/twig/twig/doc/tags/use.rst | 3 +- core/vendor/twig/twig/doc/templates.rst | 36 ++-- core/vendor/twig/twig/doc/tests/sameas.rst | 4 +- core/vendor/twig/twig/ext/twig/LICENSE | 31 --- core/vendor/twig/twig/ext/twig/php_twig.h | 2 +- core/vendor/twig/twig/ext/twig/twig.c | 12 +- core/vendor/twig/twig/lib/Twig/Autoloader.php | 2 +- core/vendor/twig/twig/lib/Twig/Compiler.php | 16 +- .../twig/twig/lib/Twig/CompilerInterface.php | 3 +- .../vendor/twig/twig/lib/Twig/Environment.php | 16 +- core/vendor/twig/twig/lib/Twig/Error.php | 8 +- .../twig/lib/Twig/ExistsLoaderInterface.php | 5 +- .../twig/twig/lib/Twig/ExpressionParser.php | 6 +- .../twig/twig/lib/Twig/Extension/Core.php | 182 +++++++++++------- .../twig/twig/lib/Twig/Extension/Sandbox.php | 2 +- .../twig/twig/lib/Twig/LexerInterface.php | 3 +- .../twig/twig/lib/Twig/Loader/Array.php | 2 + .../twig/twig/lib/Twig/Loader/Filesystem.php | 27 ++- .../twig/twig/lib/Twig/Loader/String.php | 4 +- .../twig/twig/lib/Twig/LoaderInterface.php | 2 +- core/vendor/twig/twig/lib/Twig/Node.php | 9 +- .../twig/twig/lib/Twig/Node/AutoEscape.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/Block.php | 2 +- .../twig/lib/Twig/Node/BlockReference.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/Do.php | 2 +- .../twig/lib/Twig/Node/Expression/Array.php | 2 +- .../lib/Twig/Node/Expression/AssignName.php | 2 +- .../twig/lib/Twig/Node/Expression/Binary.php | 2 +- .../Twig/Node/Expression/Binary/EndsWith.php | 10 +- .../Twig/Node/Expression/Binary/FloorDiv.php | 2 +- .../lib/Twig/Node/Expression/Binary/In.php | 2 +- .../lib/Twig/Node/Expression/Binary/NotIn.php | 2 +- .../lib/Twig/Node/Expression/Binary/Power.php | 2 +- .../lib/Twig/Node/Expression/Binary/Range.php | 2 +- .../Node/Expression/Binary/StartsWith.php | 8 +- .../Twig/Node/Expression/BlockReference.php | 2 +- .../twig/lib/Twig/Node/Expression/Call.php | 4 +- .../Node/Expression/ExtensionReference.php | 2 +- .../twig/lib/Twig/Node/Expression/GetAttr.php | 32 +-- .../twig/lib/Twig/Node/Expression/Parent.php | 2 +- .../Twig/Node/Expression/Test/Divisibleby.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/Flush.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/For.php | 2 +- .../twig/twig/lib/Twig/Node/ForLoop.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/If.php | 2 +- .../vendor/twig/twig/lib/Twig/Node/Import.php | 2 +- .../twig/twig/lib/Twig/Node/Include.php | 48 ++--- core/vendor/twig/twig/lib/Twig/Node/Macro.php | 6 +- .../vendor/twig/twig/lib/Twig/Node/Module.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/Print.php | 2 +- .../twig/twig/lib/Twig/Node/Sandbox.php | 2 +- .../twig/lib/Twig/Node/SandboxedModule.php | 44 ++++- .../twig/lib/Twig/Node/SandboxedPrint.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/Set.php | 2 +- .../twig/twig/lib/Twig/Node/Spaceless.php | 2 +- core/vendor/twig/twig/lib/Twig/Node/Text.php | 2 +- .../twig/twig/lib/Twig/NodeInterface.php | 5 +- .../twig/twig/lib/Twig/NodeTraverser.php | 2 +- .../twig/lib/Twig/NodeVisitor/Optimizer.php | 13 +- .../twig/lib/Twig/NodeVisitor/Sandbox.php | 14 +- .../twig/lib/Twig/NodeVisitorInterface.php | 2 +- .../twig/twig/lib/Twig/ParserInterface.php | 3 +- .../Sandbox/SecurityNotAllowedFilterError.php | 31 +++ .../SecurityNotAllowedFunctionError.php | 31 +++ .../Sandbox/SecurityNotAllowedTagError.php | 31 +++ .../twig/lib/Twig/Sandbox/SecurityPolicy.php | 6 +- core/vendor/twig/twig/lib/Twig/Template.php | 59 +++--- .../twig/twig/lib/Twig/TemplateInterface.php | 3 +- core/vendor/twig/twig/lib/Twig/Token.php | 18 +- .../vendor/twig/twig/lib/Twig/TokenStream.php | 6 +- .../twig/test/Twig/Tests/EnvironmentTest.php | 6 +- .../test/Twig/Tests/Extension/CoreTest.php | 18 ++ .../test/Twig/Tests/Extension/SandboxTest.php | 9 +- .../twig/test/Twig/Tests/FileCachingTest.php | 4 +- .../Fixtures/exceptions/undefined_trait.test | 2 +- .../Tests/Fixtures/expressions/bitwise.test | 2 +- .../Fixtures/expressions/divisibleby.test | 4 - .../Tests/Fixtures/expressions/ends_with.test | 14 ++ .../Tests/Fixtures/expressions/sameas.test | 4 +- .../Fixtures/expressions/starts_with.test | 10 + .../{batch_float.php => batch_float.test} | 6 +- .../Twig/Tests/Fixtures/filters/date.test | 18 +- .../Fixtures/filters/date_immutable.test | 2 + .../Twig/Tests/Fixtures/filters/default.test | 58 +++--- .../Twig/Tests/Fixtures/filters/first.test | 1 + .../Twig/Tests/Fixtures/filters/last.test | 1 + .../Twig/Tests/Fixtures/filters/slice.test | 6 + .../Twig/Tests/Fixtures/filters/split.test | 2 + .../Tests/Fixtures/filters/split_utf8.test | 24 +++ .../Tests/Fixtures/filters/urlencode.test | 8 +- .../filters/urlencode_deprecated.test | 16 ++ .../Tests/Fixtures/functions/attribute.test | 4 +- .../Fixtures/functions/include/sandbox.test | 5 +- .../recursive_block_with_inheritance.test | 21 ++ .../regression/combined_debug_info.test | 15 ++ .../Fixtures/regression/multi_word_tests.test | 10 + .../Fixtures/tags/inheritance/block_expr.test | 32 +++ .../tags/inheritance/block_expr2.test | 34 ++++ .../Fixtures/tags/macro/super_globals.test | 14 ++ .../Tests/Fixtures/tags/use/inheritance.test | 25 +++ .../Tests/Fixtures/tags/use/inheritance2.test | 24 +++ .../Tests/Fixtures/tags/use/parent_block.test | 24 +++ .../Fixtures/tags/use/parent_block2.test | 24 +++ .../Fixtures/tags/use/parent_block3.test | 38 ++++ .../twig/test/Twig/Tests/IntegrationTest.php | 12 ++ .../twig/twig/test/Twig/Tests/LexerTest.php | 17 +- .../test/Twig/Tests/NativeExtensionTest.php | 2 +- .../Tests/Node/Expression/GetAttrTest.php | 2 +- .../twig/test/Twig/Tests/Node/IncludeTest.php | 3 +- .../twig/test/Twig/Tests/Node/MacroTest.php | 6 +- .../Twig/Tests/Node/SandboxedModuleTest.php | 56 +++++- .../twig/test/Twig/Tests/TemplateTest.php | 6 +- .../twig/test/Twig/Tests/escapingTest.php | 4 +- 152 files changed, 1265 insertions(+), 598 deletions(-) delete mode 100644 core/vendor/twig/twig/ext/twig/LICENSE create mode 100644 core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php create mode 100644 core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php create mode 100644 core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php rename core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/{batch_float.php => batch_float.test} (95%) create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test create mode 100644 core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test diff --git a/composer.json b/composer.json index 117dbb81234..71c714f49b1 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "symfony/serializer": "2.5.*", "symfony/validator": "2.5.*", "symfony/yaml": "dev-master#499f7d7aa96747ad97940089bd7a1fb24ad8182a", - "twig/twig": "1.15.*", + "twig/twig": "1.16.*", "doctrine/common": "dev-master#a45d110f71c323e29f41eb0696fa230e3fa1b1b5", "doctrine/annotations": "1.2.*", "guzzlehttp/guzzle": "~5.0", diff --git a/composer.lock b/composer.lock index c61f7902030..f933c55868b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "838f4566f4f537d5f71fa46b66f263b0", + "hash": "4378dea31ef5185651bc10bd9a40e591", "packages": [ { "name": "doctrine/annotations", @@ -2373,16 +2373,16 @@ }, { "name": "twig/twig", - "version": "v1.15.1", + "version": "v1.16.2", "source": { "type": "git", "url": "https://github.com/fabpot/Twig.git", - "reference": "1fb5784662f438d7d96a541e305e28b812e2eeed" + "reference": "42f758d9fe2146d1f0470604fc05ee43580873fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fabpot/Twig/zipball/1fb5784662f438d7d96a541e305e28b812e2eeed", - "reference": "1fb5784662f438d7d96a541e305e28b812e2eeed", + "url": "https://api.github.com/repos/fabpot/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc", + "reference": "42f758d9fe2146d1f0470604fc05ee43580873fc", "shasum": "" }, "require": { @@ -2391,7 +2391,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.15-dev" + "dev-master": "1.16-dev" } }, "autoload": { @@ -2426,7 +2426,7 @@ "keywords": [ "templating" ], - "time": "2014-02-13 10:19:29" + "time": "2014-10-17 12:53:44" }, { "name": "zendframework/zend-escaper", diff --git a/core/vendor/composer/installed.json b/core/vendor/composer/installed.json index b2274770112..db7fa29b30c 100644 --- a/core/vendor/composer/installed.json +++ b/core/vendor/composer/installed.json @@ -1304,65 +1304,6 @@ "spl" ] }, - { - "name": "twig/twig", - "version": "v1.15.1", - "version_normalized": "1.15.1.0", - "source": { - "type": "git", - "url": "https://github.com/fabpot/Twig.git", - "reference": "1fb5784662f438d7d96a541e305e28b812e2eeed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fabpot/Twig/zipball/1fb5784662f438d7d96a541e305e28b812e2eeed", - "reference": "1fb5784662f438d7d96a541e305e28b812e2eeed", - "shasum": "" - }, - "require": { - "php": ">=5.2.4" - }, - "time": "2014-02-13 10:19:29", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.15-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-0": { - "Twig_": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, - { - "name": "Armin Ronacher", - "email": "armin.ronacher@active-4.com", - "role": "Project Founder" - }, - { - "name": "Twig Team", - "homepage": "https://github.com/fabpot/Twig/graphs/contributors", - "role": "Contributors" - } - ], - "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "http://twig.sensiolabs.org", - "keywords": [ - "templating" - ] - }, { "name": "doctrine/annotations", "version": "v1.2.1", @@ -2646,5 +2587,64 @@ "rest", "web service" ] + }, + { + "name": "twig/twig", + "version": "v1.16.2", + "version_normalized": "1.16.2.0", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Twig.git", + "reference": "42f758d9fe2146d1f0470604fc05ee43580873fc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fabpot/Twig/zipball/42f758d9fe2146d1f0470604fc05ee43580873fc", + "reference": "42f758d9fe2146d1f0470604fc05ee43580873fc", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "time": "2014-10-17 12:53:44", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.16-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "https://github.com/fabpot/Twig/graphs/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ] } ] diff --git a/core/vendor/twig/twig/.travis.yml b/core/vendor/twig/twig/.travis.yml index a8d71c2c86d..1fbff759939 100644 --- a/core/vendor/twig/twig/.travis.yml +++ b/core/vendor/twig/twig/.travis.yml @@ -5,6 +5,7 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 - hhvm env: diff --git a/core/vendor/twig/twig/CHANGELOG b/core/vendor/twig/twig/CHANGELOG index 6be2d655064..33b32f83811 100644 --- a/core/vendor/twig/twig/CHANGELOG +++ b/core/vendor/twig/twig/CHANGELOG @@ -1,4 +1,32 @@ -* 1.15.1 (2013-02-13) +* 1.16.2 (2014-10-17) + + * fixed timezone on dates as strings + * fixed 2-words test names when a custom node class is not used + * fixed macros when using an argument named like a PHP super global (like GET or POST) + * fixed date_modify when working with DateTimeImmutable + * optimized for loops + * fixed multi-byte characters handling in the split filter + * fixed a regression in the in operator + * fixed a regression in the slice filter + +* 1.16.1 (2014-10-10) + + * improved error reporting in a sandboxed template + * fixed missing error file/line information under certain circumstances + * fixed wrong error line number in some error messages + * fixed the in operator to use strict comparisons + * sped up the slice filter + * fixed for mb function overload mb_substr acting different + * fixed the attribute() function when passing a variable for the arguments + +* 1.16.0 (2014-07-05) + + * changed url_encode to always encode according to RFC 3986 + * fixed inheritance in a 'use'-hierarchy + * removed the __toString policy check when the sandbox is disabled + * fixed recursively calling blocks in templates with inheritance + +* 1.15.1 (2014-02-13) * fixed the conversion of the special '0000-00-00 00:00' date * added an error message when trying to import an undefined block from a trait diff --git a/core/vendor/twig/twig/composer.json b/core/vendor/twig/twig/composer.json index f1288a5611e..98b8df0f739 100644 --- a/core/vendor/twig/twig/composer.json +++ b/core/vendor/twig/twig/composer.json @@ -36,7 +36,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.15-dev" + "dev-master": "1.16-dev" } } } diff --git a/core/vendor/twig/twig/doc/api.rst b/core/vendor/twig/twig/doc/api.rst index b00d61ea9cd..775612714b1 100644 --- a/core/vendor/twig/twig/doc/api.rst +++ b/core/vendor/twig/twig/doc/api.rst @@ -166,21 +166,6 @@ Namespaced templates can be accessed via the special $twig->render('@admin/index.html', array()); -``Twig_Loader_String`` -...................... - -``Twig_Loader_String`` loads templates from strings. It's a dummy loader as -the template reference is the template source code:: - - $loader = new Twig_Loader_String(); - $twig = new Twig_Environment($loader); - - echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien')); - -This loader should only be used for unit testing as it has severe limitations: -several tags, like ``extends`` or ``include`` do not make sense to use as the -reference to the template is the template source code itself. - ``Twig_Loader_Array`` ..................... @@ -214,7 +199,7 @@ projects where storing all templates in a single PHP file might make sense. 'base.html' => '{% block content %}{% endblock %}', )); $loader2 = new Twig_Loader_Array(array( - 'index.html' => '{% extends "base.twig" %}{% block content %}Hello {{ name }}{% endblock %}', + 'index.html' => '{% extends "base.html" %}{% block content %}Hello {{ name }}{% endblock %}', 'base.html' => 'Will never be loaded', )); @@ -268,26 +253,6 @@ All loaders implement the ``Twig_LoaderInterface``:: function isFresh($name, $time); } -As an example, here is how the built-in ``Twig_Loader_String`` reads:: - - class Twig_Loader_String implements Twig_LoaderInterface - { - public function getSource($name) - { - return $name; - } - - public function getCacheKey($name) - { - return $name; - } - - public function isFresh($name, $time) - { - return false; - } - } - The ``isFresh()`` method must return ``true`` if the current cached template is still fresh, given the last modification time, or ``false`` otherwise. diff --git a/core/vendor/twig/twig/doc/deprecated.rst b/core/vendor/twig/twig/doc/deprecated.rst index 61917a8d6a7..30aaac1bac7 100644 --- a/core/vendor/twig/twig/doc/deprecated.rst +++ b/core/vendor/twig/twig/doc/deprecated.rst @@ -23,8 +23,8 @@ Extensions PEAR ---- -PEAR support will be discontinued in Twig 2.0, and no PEAR packages will be -provided. Use Composer instead. +PEAR support has been discontinued in Twig 1.15.1, and no PEAR packages are +provided anymore. Use Composer instead. Filters ------- @@ -80,6 +80,12 @@ Tests * The ``sameas`` and ``divisibleby`` tests are deprecated in favor of ``same as`` and ``divisible by`` respectively. +Nodes +----- + +* As of Twig 1.x, ``Node::toXml()`` is deprecated and will be removed in Twig + 2.0. + Interfaces ---------- diff --git a/core/vendor/twig/twig/doc/filters/batch.rst b/core/vendor/twig/twig/doc/filters/batch.rst index b0b9964eb98..30dd7823547 100644 --- a/core/vendor/twig/twig/doc/filters/batch.rst +++ b/core/vendor/twig/twig/doc/filters/batch.rst @@ -2,7 +2,7 @@ ========= .. versionadded:: 1.12.3 - The batch filter was added in Twig 1.12.3. + The ``batch`` filter was added in Twig 1.12.3. The ``batch`` filter "batches" items by returning a list of lists with the given number of items. If you provide a second parameter, it is used to fill diff --git a/core/vendor/twig/twig/doc/filters/convert_encoding.rst b/core/vendor/twig/twig/doc/filters/convert_encoding.rst index c417e128736..f4ebe5807d9 100644 --- a/core/vendor/twig/twig/doc/filters/convert_encoding.rst +++ b/core/vendor/twig/twig/doc/filters/convert_encoding.rst @@ -21,8 +21,8 @@ is the input charset: Arguments --------- -* ``from``: The input charset * ``to``: The output charset +* ``from``: The input charset .. _`iconv`: http://php.net/iconv .. _`mbstring`: http://php.net/mbstring diff --git a/core/vendor/twig/twig/doc/filters/first.rst b/core/vendor/twig/twig/doc/filters/first.rst index 4295e83340c..674c1f9ed12 100644 --- a/core/vendor/twig/twig/doc/filters/first.rst +++ b/core/vendor/twig/twig/doc/filters/first.rst @@ -2,7 +2,7 @@ ========= .. versionadded:: 1.12.2 - The first filter was added in Twig 1.12.2. + The ``first`` filter was added in Twig 1.12.2. The ``first`` filter returns the first "element" of a sequence, a mapping, or a string: diff --git a/core/vendor/twig/twig/doc/filters/json_encode.rst b/core/vendor/twig/twig/doc/filters/json_encode.rst index 9821b11eaa1..a39bb476eae 100644 --- a/core/vendor/twig/twig/doc/filters/json_encode.rst +++ b/core/vendor/twig/twig/doc/filters/json_encode.rst @@ -1,7 +1,7 @@ ``json_encode`` =============== -The ``json_encode`` filter returns the JSON representation of a string: +The ``json_encode`` filter returns the JSON representation of a value: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/last.rst b/core/vendor/twig/twig/doc/filters/last.rst index 723c0b57e98..345b6573d73 100644 --- a/core/vendor/twig/twig/doc/filters/last.rst +++ b/core/vendor/twig/twig/doc/filters/last.rst @@ -2,7 +2,7 @@ ======== .. versionadded:: 1.12.2 - The last filter was added in Twig 1.12.2. + The ``last`` filter was added in Twig 1.12.2. The ``last`` filter returns the last "element" of a sequence, a mapping, or a string: diff --git a/core/vendor/twig/twig/doc/filters/length.rst b/core/vendor/twig/twig/doc/filters/length.rst index 5e0f73a4372..1f783b3dd10 100644 --- a/core/vendor/twig/twig/doc/filters/length.rst +++ b/core/vendor/twig/twig/doc/filters/length.rst @@ -1,7 +1,7 @@ ``length`` ========== -The ``length`` filters returns the number of items of a sequence or mapping, or +The ``length`` filter returns the number of items of a sequence or mapping, or the length of a string: .. code-block:: jinja diff --git a/core/vendor/twig/twig/doc/filters/merge.rst b/core/vendor/twig/twig/doc/filters/merge.rst index 05a2ae7d0ee..cb8b1b2230e 100644 --- a/core/vendor/twig/twig/doc/filters/merge.rst +++ b/core/vendor/twig/twig/doc/filters/merge.rst @@ -39,3 +39,9 @@ overridden. {% set items = { 'apple': 'unknown' }|merge(items) %} {# items now contains { 'apple': 'fruit', 'orange': 'fruit' } #} + +.. note:: + + Internally, Twig uses the PHP `array_merge`_ function. + +.. _`array_merge`: http://php.net/array_merge diff --git a/core/vendor/twig/twig/doc/filters/nl2br.rst b/core/vendor/twig/twig/doc/filters/nl2br.rst index 694c672496f..5c923e143aa 100644 --- a/core/vendor/twig/twig/doc/filters/nl2br.rst +++ b/core/vendor/twig/twig/doc/filters/nl2br.rst @@ -2,7 +2,7 @@ ========= .. versionadded:: 1.5 - The nl2br filter was added in Twig 1.5. + The ``nl2br`` filter was added in Twig 1.5. The ``nl2br`` filter inserts HTML line breaks before all newlines in a string: diff --git a/core/vendor/twig/twig/doc/filters/number_format.rst b/core/vendor/twig/twig/doc/filters/number_format.rst index 3e60691f819..3114e8451d4 100644 --- a/core/vendor/twig/twig/doc/filters/number_format.rst +++ b/core/vendor/twig/twig/doc/filters/number_format.rst @@ -2,7 +2,7 @@ ================= .. versionadded:: 1.5 - The number_format filter was added in Twig 1.5 + The ``number_format`` filter was added in Twig 1.5 The ``number_format`` filter formats numbers. It is a wrapper around PHP's `number_format`_ function: diff --git a/core/vendor/twig/twig/doc/filters/raw.rst b/core/vendor/twig/twig/doc/filters/raw.rst index a9900c7bbcd..e5e5b12ecd7 100644 --- a/core/vendor/twig/twig/doc/filters/raw.rst +++ b/core/vendor/twig/twig/doc/filters/raw.rst @@ -10,3 +10,27 @@ if ``raw`` is the last filter applied to it: {% autoescape %} {{ var|raw }} {# var won't be escaped #} {% endautoescape %} + +.. note:: + + Be careful when using the ``raw`` filter inside expressions: + + .. code-block:: jinja + + {% autoescape %} + {% set hello = 'Hello' %} + {% set hola = 'Hola' %} + + {{ false ? 'Hola' : hello|raw }} + does not render the same as + {{ false ? hola : hello|raw }} + but renders the same as + {{ (false ? hola : hello)|raw }} + {% endautoescape %} + + The first ternary statement is not escaped: ``hello`` is marked as being + safe and Twig does not escape static values (see + :doc:`escape<../tags/autoescape>`). In the second ternary statement, even + if ``hello`` is marked as safe, ``hola`` remains unsafe and so is the whole + expression. The third ternary statement is marked as safe and the result is + not escaped. diff --git a/core/vendor/twig/twig/doc/filters/slice.rst b/core/vendor/twig/twig/doc/filters/slice.rst index c76c61c11e0..a8566641234 100644 --- a/core/vendor/twig/twig/doc/filters/slice.rst +++ b/core/vendor/twig/twig/doc/filters/slice.rst @@ -2,7 +2,7 @@ =========== .. versionadded:: 1.6 - The slice filter was added in Twig 1.6. + The ``slice`` filter was added in Twig 1.6. The ``slice`` filter extracts a slice of a sequence, a mapping, or a string: @@ -41,7 +41,7 @@ As syntactic sugar, you can also use the ``[]`` notation: {{ '12345'[2:] }} {# will display "345" #} The ``slice`` filter works as the `array_slice`_ PHP function for arrays and -`substr`_ for strings. +`mb_substr`_ for strings with a fallback to `substr`_. If the start is non-negative, the sequence will start at that start in the variable. If start is negative, the sequence will start that far from the end @@ -67,4 +67,5 @@ Arguments .. _`Traversable`: http://php.net/manual/en/class.traversable.php .. _`array_slice`: http://php.net/array_slice +.. _`mb_substr` : http://php.net/mb-substr .. _`substr`: http://php.net/substr diff --git a/core/vendor/twig/twig/doc/filters/split.rst b/core/vendor/twig/twig/doc/filters/split.rst index 3db81411dec..bbc6d798f28 100644 --- a/core/vendor/twig/twig/doc/filters/split.rst +++ b/core/vendor/twig/twig/doc/filters/split.rst @@ -2,15 +2,15 @@ ========= .. versionadded:: 1.10.3 - The split filter was added in Twig 1.10.3. + The ``split`` filter was added in Twig 1.10.3. The ``split`` filter splits a string by the given delimiter and returns a list of strings: .. code-block:: jinja - {{ "one,two,three"|split(',') }} - {# returns ['one', 'two', 'three'] #} + {% set foo = "one,two,three"|split(',') %} + {# foo contains ['one', 'two', 'three'] #} You can also pass a ``limit`` argument: @@ -24,19 +24,19 @@ You can also pass a ``limit`` argument: .. code-block:: jinja - {{ "one,two,three,four,five"|split(',', 3) }} - {# returns ['one', 'two', 'three,four,five'] #} + {% set foo = "one,two,three,four,five"|split(',', 3) %} + {# foo contains ['one', 'two', 'three,four,five'] #} If the ``delimiter`` is an empty string, then value will be split by equal chunks. Length is set by the ``limit`` argument (one character by default). .. code-block:: jinja - {{ "123"|split('') }} - {# returns ['1', '2', '3'] #} + {% set foo = "123"|split('') %} + {# foo contains ['1', '2', '3'] #} - {{ "aabbcc"|split('', 2) }} - {# returns ['aa', 'bb', 'cc'] #} + {% set bar = "aabbcc"|split('', 2) %} + {# bar contains ['aa', 'bb', 'cc'] #} .. note:: diff --git a/core/vendor/twig/twig/doc/filters/trim.rst b/core/vendor/twig/twig/doc/filters/trim.rst index 0c5b32edb3e..4ddb2083bfb 100644 --- a/core/vendor/twig/twig/doc/filters/trim.rst +++ b/core/vendor/twig/twig/doc/filters/trim.rst @@ -2,7 +2,7 @@ ======== .. versionadded:: 1.6.2 - The trim filter was added in Twig 1.6.2. + The ``trim`` filter was added in Twig 1.6.2. The ``trim`` filter strips whitespace (or other characters) from the beginning and end of a string: diff --git a/core/vendor/twig/twig/doc/filters/url_encode.rst b/core/vendor/twig/twig/doc/filters/url_encode.rst index 7a35ed152f6..5944e59cd5b 100644 --- a/core/vendor/twig/twig/doc/filters/url_encode.rst +++ b/core/vendor/twig/twig/doc/filters/url_encode.rst @@ -4,6 +4,10 @@ .. versionadded:: 1.12.3 Support for encoding an array as query string was added in Twig 1.12.3. +.. versionadded:: 1.16.0 + The ``raw`` argument was removed in Twig 1.16.0. Twig now always encodes + according to RFC 3986. + The ``url_encode`` filter percent encodes a given string as URL segment or an array as query string: @@ -12,7 +16,7 @@ or an array as query string: {{ "path-seg*ment"|url_encode }} {# outputs "path-seg%2Ament" #} - {{ "string with spaces"|url_encode(true) }} + {{ "string with spaces"|url_encode }} {# outputs "string%20with%20spaces" #} {{ {'param': 'value', 'foo': 'bar'}|url_encode }} @@ -21,7 +25,9 @@ or an array as query string: .. note:: Internally, Twig uses the PHP `urlencode`_ (or `rawurlencode`_ if you pass - ``true`` as the first parameter) or the `http_build_query`_ function. + ``true`` as the first parameter) or the `http_build_query`_ function. Note + that as of Twig 1.16.0, ``urlencode`` **always** uses ``rawurlencode`` (the + ``raw`` argument was removed.) .. _`urlencode`: http://php.net/urlencode .. _`rawurlencode`: http://php.net/rawurlencode diff --git a/core/vendor/twig/twig/doc/functions/date.rst b/core/vendor/twig/twig/doc/functions/date.rst index 9442c39ff21..714e08c47b2 100644 --- a/core/vendor/twig/twig/doc/functions/date.rst +++ b/core/vendor/twig/twig/doc/functions/date.rst @@ -15,7 +15,7 @@ Converts an argument to a date to allow date comparison: {# do something #} {% endif %} -The argument must be in a format supported by the `date`_ function. +The argument must be in one of PHP’s supported `date and time formats`_. You can pass a timezone as the second argument: @@ -49,4 +49,4 @@ Arguments * ``date``: The date * ``timezone``: The timezone -.. _`date`: http://www.php.net/date +.. _`date and time formats`: http://php.net/manual/en/datetime.formats.php diff --git a/core/vendor/twig/twig/doc/functions/dump.rst b/core/vendor/twig/twig/doc/functions/dump.rst index 54f8d4e1354..a231f089e25 100644 --- a/core/vendor/twig/twig/doc/functions/dump.rst +++ b/core/vendor/twig/twig/doc/functions/dump.rst @@ -2,7 +2,7 @@ ======== .. versionadded:: 1.5 - The dump function was added in Twig 1.5. + The ``dump`` function was added in Twig 1.5. The ``dump`` function dumps information about a template variable. This is mostly useful to debug a template that does not behave as expected by diff --git a/core/vendor/twig/twig/doc/functions/include.rst b/core/vendor/twig/twig/doc/functions/include.rst index 8feb0f17913..33bd56d116b 100644 --- a/core/vendor/twig/twig/doc/functions/include.rst +++ b/core/vendor/twig/twig/doc/functions/include.rst @@ -2,7 +2,7 @@ =========== .. versionadded:: 1.12 - The include function was added in Twig 1.12. + The ``include`` function was added in Twig 1.12. The ``include`` function returns the rendered content of a template: diff --git a/core/vendor/twig/twig/doc/functions/max.rst b/core/vendor/twig/twig/doc/functions/max.rst index bdc5b753869..6f3cfc53523 100644 --- a/core/vendor/twig/twig/doc/functions/max.rst +++ b/core/vendor/twig/twig/doc/functions/max.rst @@ -15,5 +15,6 @@ When called with a mapping, max ignores keys and only compares values: .. code-block:: jinja - {{ max({2: "two", 1: "one", 3: "three", 5: "five", 4: "for"}) }} - {# return "two" #} + {{ max({2: "e", 1: "a", 3: "b", 5: "d", 4: "c"}) }} + {# returns "e" #} + diff --git a/core/vendor/twig/twig/doc/functions/min.rst b/core/vendor/twig/twig/doc/functions/min.rst index b924b0318dd..7b6a65e1033 100644 --- a/core/vendor/twig/twig/doc/functions/min.rst +++ b/core/vendor/twig/twig/doc/functions/min.rst @@ -15,5 +15,6 @@ When called with a mapping, min ignores keys and only compares values: .. code-block:: jinja - {{ min({2: "two", 1: "one", 3: "three", 5: "five", 4: "for"}) }} - {# return "five" #} + {{ min({2: "e", 3: "a", 1: "b", 5: "d", 4: "c"}) }} + {# returns "a" #} + diff --git a/core/vendor/twig/twig/doc/functions/random.rst b/core/vendor/twig/twig/doc/functions/random.rst index acbffe557fd..168e74f8f7d 100644 --- a/core/vendor/twig/twig/doc/functions/random.rst +++ b/core/vendor/twig/twig/doc/functions/random.rst @@ -2,7 +2,7 @@ ========== .. versionadded:: 1.5 - The random function was added in Twig 1.5. + The ``random`` function was added in Twig 1.5. .. versionadded:: 1.6 String and integer handling was added in Twig 1.6. diff --git a/core/vendor/twig/twig/doc/functions/source.rst b/core/vendor/twig/twig/doc/functions/source.rst index defa5fbc551..8ff39c2df1c 100644 --- a/core/vendor/twig/twig/doc/functions/source.rst +++ b/core/vendor/twig/twig/doc/functions/source.rst @@ -2,7 +2,7 @@ ========== .. versionadded:: 1.15 - The source function was added in Twig 1.15. + The ``source`` function was added in Twig 1.15. The ``source`` function returns the content of a template without rendering it: diff --git a/core/vendor/twig/twig/doc/functions/template_from_string.rst b/core/vendor/twig/twig/doc/functions/template_from_string.rst index 95d92563126..ce6a60dc0b8 100644 --- a/core/vendor/twig/twig/doc/functions/template_from_string.rst +++ b/core/vendor/twig/twig/doc/functions/template_from_string.rst @@ -2,7 +2,7 @@ ======================== .. versionadded:: 1.11 - The template_from_string function was added in Twig 1.11. + The ``template_from_string`` function was added in Twig 1.11. The ``template_from_string`` function loads a template from a string: diff --git a/core/vendor/twig/twig/doc/index.rst b/core/vendor/twig/twig/doc/index.rst index 3109c730b6e..358bd738ed0 100644 --- a/core/vendor/twig/twig/doc/index.rst +++ b/core/vendor/twig/twig/doc/index.rst @@ -5,15 +5,15 @@ Twig :maxdepth: 2 intro + installation templates api advanced internals + deprecated recipes coding_standards tags/index filters/index functions/index tests/index - installation - deprecated diff --git a/core/vendor/twig/twig/doc/installation.rst b/core/vendor/twig/twig/doc/installation.rst index 278ef61ca92..2d19f755e8c 100644 --- a/core/vendor/twig/twig/doc/installation.rst +++ b/core/vendor/twig/twig/doc/installation.rst @@ -9,51 +9,39 @@ Installing the Twig PHP package Installing via Composer (recommended) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -1. Install Composer in your project: +Install `Composer`_ and run the following command to get the latest version: .. code-block:: bash - curl -s http://getcomposer.org/installer | php - -2. Create a ``composer.json`` file in your project root: - -.. code-block:: javascript - - { - "require": { - "twig/twig": "1.*" - } - } - -3. Install via Composer - -.. code-block:: bash - - php composer.phar install - -.. note:: - If you want to learn more about Composer, the ``composer.json`` file syntax - and its usage, you can read the `online documentation`_. + composer require twig/twig:~1.0 Installing from the tarball release ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. Download the most recent tarball from the `download page`_ -2. Unpack the tarball -3. Move the files somewhere in your project +2. Verify the integrity of the tarball http://fabien.potencier.org/article/73/signing-project-releases +3. Unpack the tarball +4. Move the files somewhere in your project Installing the development version ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -1. Install Git -2. ``git clone git://github.com/fabpot/Twig.git`` +.. code-block:: bash + + git clone git://github.com/fabpot/Twig.git Installing the PEAR package ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -1. Install PEAR -2. ``pear channel-discover pear.twig-project.org`` -3. ``pear install twig/Twig`` (or ``pear install twig/Twig-beta``) +.. note:: + + Using PEAR for installing Twig is deprecated and Twig 1.15.1 was the last + version published on the PEAR channel; use Composer instead. + +.. code-block:: bash + + pear channel-discover pear.twig-project.org + pear install twig/Twig Installing the C extension -------------------------- @@ -61,24 +49,31 @@ Installing the C extension .. versionadded:: 1.4 The C extension was added in Twig 1.4. +.. note:: + The C extension is **optional** but as it brings some nice performance + improvements, you might want to install it in your production environment. + Twig comes with a C extension that enhances the performance of the Twig -runtime engine. - -You can install it via PEAR: - -1. Install PEAR -2. ``pear channel-discover pear.twig-project.org`` -3. ``pear install twig/CTwig`` (or ``pear install twig/CTwig-beta``) - -Or manually like any other PHP extension: +runtime engine; install it like any other PHP extensions: .. code-block:: bash - $ cd ext/twig - $ phpize - $ ./configure - $ make - $ make install + cd ext/twig + phpize + ./configure + make + make install + +.. note:: + + You can also install the C extension via PEAR (note that this method is + deprecated and newer versions of Twig are not available on the PEAR + channel): + + .. code-block:: bash + + pear channel-discover pear.twig-project.org + pear install twig/CTwig For Windows: @@ -90,15 +85,15 @@ For Windows: .. tip:: - For Windows ZendServer, TS is not enabled as mentionned in `Zend Server + For Windows ZendServer, ZTS is not enabled as mentioned in `Zend Server FAQ`_. - You have to use `configure --disable-all --disable-zts --enable-cli - --enable-twig=shared` to be able to build the twig C extension for + You have to use ``configure --disable-all --disable-zts --enable-cli + --enable-twig=shared`` to be able to build the twig C extension for ZendServer. The built DLL will be available in - C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release + ``C:\\php-sdk\\phpdev\\vcXX\\x86\\php-source-directory\\Release`` Finally, enable the extension in your ``php.ini`` configuration file: @@ -113,6 +108,6 @@ PHP code but only provides an optimized version of the ``Twig_Template::getAttribute()`` method. .. _`download page`: https://github.com/fabpot/Twig/tags -.. _`online documentation`: http://getcomposer.org/doc +.. _`Composer`: https://getcomposer.org/download/ .. _`PHP documentation`: https://wiki.php.net/internals/windows/stepbystepbuild .. _`Zend Server FAQ`: http://www.zend.com/en/products/server/faq#faqD6 diff --git a/core/vendor/twig/twig/doc/internals.rst b/core/vendor/twig/twig/doc/internals.rst index 16f425adec9..a68796b9cf6 100644 --- a/core/vendor/twig/twig/doc/internals.rst +++ b/core/vendor/twig/twig/doc/internals.rst @@ -124,7 +124,7 @@ using):: { // line 1 echo "Hello "; - echo twig_escape_filter($this->env, $this->getContext($context, "name"), "ndex", null, true); + echo twig_escape_filter($this->env, $this->getContext($context, "name"), "html", null, true); } // some more code diff --git a/core/vendor/twig/twig/doc/intro.rst b/core/vendor/twig/twig/doc/intro.rst index 9f0cdf02774..3a7c1d4e59e 100644 --- a/core/vendor/twig/twig/doc/intro.rst +++ b/core/vendor/twig/twig/doc/intro.rst @@ -33,7 +33,7 @@ The recommended way to install Twig is via Composer: .. code-block:: bash - composer require twig/twig:1.* + composer require "twig/twig:~1.0" .. note:: @@ -50,12 +50,14 @@ This section gives you a brief introduction to the PHP API for Twig. require_once '/path/to/vendor/autoload.php'; - $loader = new Twig_Loader_String(); + $loader = new Twig_Loader_Array( + 'index' => 'Hello {{ name }}!', + ); $twig = new Twig_Environment($loader); - echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien')); + echo $twig->render('index', array('name' => 'Fabien')); -Twig uses a loader (``Twig_Loader_String``) to locate templates, and an +Twig uses a loader (``Twig_Loader_Array``) to locate templates, and an environment (``Twig_Environment``) to store the configuration. The ``render()`` method loads the template passed as a first argument and diff --git a/core/vendor/twig/twig/doc/recipes.rst b/core/vendor/twig/twig/doc/recipes.rst index bfdfc0d55ed..64090d913f2 100644 --- a/core/vendor/twig/twig/doc/recipes.rst +++ b/core/vendor/twig/twig/doc/recipes.rst @@ -242,7 +242,7 @@ does not return ``false``. Validating the Template Syntax ------------------------------ -When template code is providing by a third-party (through a web interface for +When template code is provided by a third-party (through a web interface for instance), it might be interesting to validate the template syntax before saving it. If the template code is stored in a `$template` variable, here is how you can do it:: diff --git a/core/vendor/twig/twig/doc/tags/autoescape.rst b/core/vendor/twig/twig/doc/tags/autoescape.rst index c5ff0c2c3c5..4208d1a3100 100644 --- a/core/vendor/twig/twig/doc/tags/autoescape.rst +++ b/core/vendor/twig/twig/doc/tags/autoescape.rst @@ -65,6 +65,18 @@ Functions returning template data (like :doc:`macros` and Twig is smart enough to not escape an already escaped value by the :doc:`escape<../filters/escape>` filter. +.. note:: + + Twig does not escape static expressions: + + .. code-block:: jinja + + {% set hello = "Hello" %} + {{ hello }} + {{ "world" }} + + Will be rendered "Hello **world**". + .. note:: The chapter :doc:`Twig for Developers<../api>` gives more information diff --git a/core/vendor/twig/twig/doc/tags/do.rst b/core/vendor/twig/twig/doc/tags/do.rst index eca63d0ad05..1c344e302c6 100644 --- a/core/vendor/twig/twig/doc/tags/do.rst +++ b/core/vendor/twig/twig/doc/tags/do.rst @@ -2,7 +2,7 @@ ====== .. versionadded:: 1.5 - The do tag was added in Twig 1.5. + The ``do`` tag was added in Twig 1.5. The ``do`` tag works exactly like the regular variable expression (``{{ ... }}``) just that it doesn't print anything: diff --git a/core/vendor/twig/twig/doc/tags/extends.rst b/core/vendor/twig/twig/doc/tags/extends.rst index d962a30fb60..1ad2b12b1fb 100644 --- a/core/vendor/twig/twig/doc/tags/extends.rst +++ b/core/vendor/twig/twig/doc/tags/extends.rst @@ -186,8 +186,8 @@ In this example, the template will extend the "minimum.html" layout template if the ``standalone`` variable evaluates to ``true``, and "base.html" otherwise. -How blocks work? ----------------- +How do blocks work? +------------------- A block provides a way to change how a certain part of a template is rendered but it does not interfere in any way with the logic around it. diff --git a/core/vendor/twig/twig/doc/tags/if.rst b/core/vendor/twig/twig/doc/tags/if.rst index d7a1451c4a7..273207d0b90 100644 --- a/core/vendor/twig/twig/doc/tags/if.rst +++ b/core/vendor/twig/twig/doc/tags/if.rst @@ -41,3 +41,20 @@ more complex ``expressions`` there too: {% else %} Kenny looks okay --- so far {% endif %} + +.. note:: + + The rules to determine if an expression is ``true`` or ``false`` are the + same as in PHP; here are the edge cases rules: + + ====================== ==================== + Value Boolean evaluation + ====================== ==================== + empty string false + numeric zero false + whitespace-only string true + empty array false + null false + non-empty array true + object true + ====================== ==================== diff --git a/core/vendor/twig/twig/doc/tags/use.rst b/core/vendor/twig/twig/doc/tags/use.rst index e403632dc7d..a2f3af09024 100644 --- a/core/vendor/twig/twig/doc/tags/use.rst +++ b/core/vendor/twig/twig/doc/tags/use.rst @@ -39,7 +39,8 @@ The ``use`` statement tells Twig to import the blocks defined in .. code-block:: jinja - # blocks.html + {# blocks.html #} + {% block sidebar %}{% endblock %} In this example, the ``use`` statement imports the ``sidebar`` block into the diff --git a/core/vendor/twig/twig/doc/templates.rst b/core/vendor/twig/twig/doc/templates.rst index 6d9d6ba4bd7..82b6f0c742d 100644 --- a/core/vendor/twig/twig/doc/templates.rst +++ b/core/vendor/twig/twig/doc/templates.rst @@ -15,7 +15,7 @@ A template contains **variables** or **expressions**, which get replaced with values when the template is evaluated, and **tags**, which control the logic of the template. -Below is a minimal template that illustrates a few basics. We will cover the +Below is a minimal template that illustrates a few basics. We will cover further details later on: .. code-block:: html+jinja @@ -58,14 +58,15 @@ Many IDEs support syntax highlighting and auto-completion for Twig: * *Komodo* and *Komodo Edit* via the Twig highlight/syntax check mode * *Notepad++* via the `Notepad++ Twig Highlighter`_ * *Emacs* via `web-mode.el`_ +* *Atom* via the `PHP-twig for atom`_ Variables --------- -The application passes variables to the templates you can mess around in the -template. Variables may have attributes or elements on them you can access -too. How a variable looks like heavily depends on the application providing -those. +The application passes variables to the templates for manipulation in the +template. Variables may have attributes or elements you can access, +too. The visual representation of a variable depends heavily on the application providing +it. You can use a dot (``.``) to access attributes of a variable (methods or properties of a PHP object, or items of a PHP array), or the so-called @@ -88,16 +89,16 @@ access the variable attribute: .. note:: It's important to know that the curly braces are *not* part of the - variable but the print statement. If you access variables inside tags - don't put the braces around. + variable but the print statement. When accessing variables inside tags, + don't put the braces around them. -If a variable or attribute does not exist, you will get back a ``null`` value -when the ``strict_variables`` option is set to ``false``, otherwise Twig will -throw an error (see :ref:`environment options`). +If a variable or attribute does not exist, you will receive a ``null`` value +when the ``strict_variables`` option is set to ``false``; alternatively, if ``strict_variables`` +is set, Twig will throw an error (see :ref:`environment options`). .. sidebar:: Implementation - For convenience sake ``foo.bar`` does the following things on the PHP + For convenience's sake ``foo.bar`` does the following things on the PHP layer: * check if ``foo`` is an array and ``bar`` a valid element; @@ -115,7 +116,7 @@ throw an error (see :ref:`environment options`). .. note:: - If you want to get a dynamic attribute on a variable, use the + If you want to access a dynamic attribute of a variable, use the :doc:`attribute` function instead. Global Variables @@ -161,7 +162,7 @@ example will join a list by commas: {{ list|join(', ') }} -To apply a filter on a section of code, wrap it with the +To apply a filter on a section of code, wrap it in the :doc:`filter` tag: .. code-block:: jinja @@ -170,7 +171,7 @@ To apply a filter on a section of code, wrap it with the This text becomes uppercase {% endfilter %} -Go to the :doc:`filters` page to learn more about the built-in +Go to the :doc:`filters` page to learn more about built-in filters. Functions @@ -222,7 +223,7 @@ to change the default value: {# the first argument is the date format, which defaults to the global date format if null is passed #} {{ "now"|date(null, "Europe/Paris") }} - {# or skip the format value by using a named argument for the timezone #} + {# or skip the format value by using a named argument for the time zone #} {{ "now"|date(timezone="Europe/Paris") }} You can also use both positional and named arguments in one call, in which @@ -327,7 +328,7 @@ allows you to build a base "skeleton" template that contains all the common elements of your site and defines **blocks** that child templates can override. -Sounds complicated but is very basic. It's easier to understand it by +Sounds complicated but it is very basic. It's easier to understand it by starting with an example. Let's define a base template, ``base.html``, which defines a simple HTML @@ -692,7 +693,7 @@ string: .. code-block:: jinja - {% if phone matches '{^[\d\.]+$}' %} + {% if phone matches '/^[\\d\\.]+$/' %} {% endif %} Containment Operator @@ -871,3 +872,4 @@ Extension` chapter. .. _`Notepad++ Twig Highlighter`: https://github.com/Banane9/notepadplusplus-twig .. _`web-mode.el`: http://web-mode.org/ .. _`regular expressions`: http://php.net/manual/en/pcre.pattern.php +.. _`PHP-twig for atom`: https://github.com/reesef/php-twig diff --git a/core/vendor/twig/twig/doc/tests/sameas.rst b/core/vendor/twig/twig/doc/tests/sameas.rst index 6ed56d86960..16f904d5c6c 100644 --- a/core/vendor/twig/twig/doc/tests/sameas.rst +++ b/core/vendor/twig/twig/doc/tests/sameas.rst @@ -4,8 +4,8 @@ .. versionadded:: 1.14.2 The ``same as`` test was added in Twig 1.14.2 as an alias for ``sameas``. -``same as`` checks if a variable points to the same memory address than -another variable: +``same as`` checks if a variable is the same as another variable. +This is the equivalent to ``===`` in PHP: .. code-block:: jinja diff --git a/core/vendor/twig/twig/ext/twig/LICENSE b/core/vendor/twig/twig/ext/twig/LICENSE deleted file mode 100644 index 3384cc5589d..00000000000 --- a/core/vendor/twig/twig/ext/twig/LICENSE +++ /dev/null @@ -1,31 +0,0 @@ -Copyright (c) 2009-2013 by the Twig Team, see AUTHORS for more details. - -Some rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * The names of the contributors may not be used to endorse or - promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/core/vendor/twig/twig/ext/twig/php_twig.h b/core/vendor/twig/twig/ext/twig/php_twig.h index 858c0d8059f..e116b4c2d34 100644 --- a/core/vendor/twig/twig/ext/twig/php_twig.h +++ b/core/vendor/twig/twig/ext/twig/php_twig.h @@ -15,7 +15,7 @@ #ifndef PHP_TWIG_H #define PHP_TWIG_H -#define PHP_TWIG_VERSION "1.15.1" +#define PHP_TWIG_VERSION "1.16.2" #include "php.h" diff --git a/core/vendor/twig/twig/ext/twig/twig.c b/core/vendor/twig/twig/ext/twig/twig.c index 5cb923f5441..5c482bedb7c 100644 --- a/core/vendor/twig/twig/ext/twig/twig.c +++ b/core/vendor/twig/twig/ext/twig/twig.c @@ -830,7 +830,11 @@ PHP_FUNCTION(twig_template_get_attributes) } elseif (is_object($object)) { $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object)); } elseif (is_array($object)) { - $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + if (empty($object)) { + $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); + } else { + $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + } } elseif (Twig_Template::ARRAY_CALL === $type) { $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } else { @@ -845,7 +849,11 @@ PHP_FUNCTION(twig_template_get_attributes) } else if (Z_TYPE_P(object) == IS_OBJECT) { TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); } else if (Z_TYPE_P(object) == IS_ARRAY) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist", item, TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC)); + if (0 == zend_hash_num_elements(Z_ARRVAL_P(object))) { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty", item); + } else { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist", item, TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC)); + } } else { char *type_name = zend_zval_type_name(object); Z_ADDREF_P(object); diff --git a/core/vendor/twig/twig/lib/Twig/Autoloader.php b/core/vendor/twig/twig/lib/Twig/Autoloader.php index 0ae11276981..42f16f094a6 100644 --- a/core/vendor/twig/twig/lib/Twig/Autoloader.php +++ b/core/vendor/twig/twig/lib/Twig/Autoloader.php @@ -19,7 +19,7 @@ class Twig_Autoloader /** * Registers Twig_Autoloader as an SPL autoloader. * - * @param Boolean $prepend Whether to prepend the autoloader or not. + * @param bool $prepend Whether to prepend the autoloader or not. */ public static function register($prepend = false) { diff --git a/core/vendor/twig/twig/lib/Twig/Compiler.php b/core/vendor/twig/twig/lib/Twig/Compiler.php index bb6b129e32e..93dc87660d8 100644 --- a/core/vendor/twig/twig/lib/Twig/Compiler.php +++ b/core/vendor/twig/twig/lib/Twig/Compiler.php @@ -66,7 +66,7 @@ class Twig_Compiler implements Twig_CompilerInterface * Compiles a node. * * @param Twig_NodeInterface $node The node to compile - * @param integer $indentation The current indentation + * @param int $indentation The current indentation * * @return Twig_Compiler The current compiler instance */ @@ -74,6 +74,7 @@ class Twig_Compiler implements Twig_CompilerInterface { $this->lastLine = null; $this->source = ''; + $this->debugInfo = array(); $this->sourceOffset = 0; // source code starts at 1 (as we then increment it when we encounter new lines) $this->sourceLine = 1; @@ -181,14 +182,14 @@ class Twig_Compiler implements Twig_CompilerInterface } elseif (is_array($value)) { $this->raw('array('); $first = true; - foreach ($value as $key => $value) { + foreach ($value as $key => $v) { if (!$first) { $this->raw(', '); } $first = false; $this->repr($key); $this->raw(' => '); - $this->repr($value); + $this->repr($v); } $this->raw(')'); } else { @@ -236,7 +237,7 @@ class Twig_Compiler implements Twig_CompilerInterface /** * Indents the generated code. * - * @param integer $step The number of indentation to add + * @param int $step The number of indentation to add * * @return Twig_Compiler The current compiler instance */ @@ -250,7 +251,7 @@ class Twig_Compiler implements Twig_CompilerInterface /** * Outdents the generated code. * - * @param integer $step The number of indentation to remove + * @param int $step The number of indentation to remove * * @return Twig_Compiler The current compiler instance * @@ -267,4 +268,9 @@ class Twig_Compiler implements Twig_CompilerInterface return $this; } + + public function getVarName() + { + return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false)); + } } diff --git a/core/vendor/twig/twig/lib/Twig/CompilerInterface.php b/core/vendor/twig/twig/lib/Twig/CompilerInterface.php index e293ec9113b..272c7672f68 100644 --- a/core/vendor/twig/twig/lib/Twig/CompilerInterface.php +++ b/core/vendor/twig/twig/lib/Twig/CompilerInterface.php @@ -13,7 +13,8 @@ * Interface implemented by compiler classes. * * @author Fabien Potencier - * @deprecated since 1.12 (to be removed in 2.0) + * + * @deprecated since 1.12 (to be removed in 3.0) */ interface Twig_CompilerInterface { diff --git a/core/vendor/twig/twig/lib/Twig/Environment.php b/core/vendor/twig/twig/lib/Twig/Environment.php index 1fec1a369d5..17e88ab2a59 100644 --- a/core/vendor/twig/twig/lib/Twig/Environment.php +++ b/core/vendor/twig/twig/lib/Twig/Environment.php @@ -16,7 +16,7 @@ */ class Twig_Environment { - const VERSION = '1.15.1'; + const VERSION = '1.16.2'; protected $charset; protected $loader; @@ -154,7 +154,7 @@ class Twig_Environment /** * Checks if debug mode is enabled. * - * @return Boolean true if debug mode is enabled, false otherwise + * @return bool true if debug mode is enabled, false otherwise */ public function isDebug() { @@ -180,7 +180,7 @@ class Twig_Environment /** * Checks if the auto_reload option is enabled. * - * @return Boolean true if auto_reload is enabled, false otherwise + * @return bool true if auto_reload is enabled, false otherwise */ public function isAutoReload() { @@ -206,7 +206,7 @@ class Twig_Environment /** * Checks if the strict_variables option is enabled. * - * @return Boolean true if strict_variables is enabled, false otherwise + * @return bool true if strict_variables is enabled, false otherwise */ public function isStrictVariables() { @@ -256,7 +256,7 @@ class Twig_Environment * Gets the template class associated with the given string. * * @param string $name The name for which to calculate the template class name - * @param integer $index The index if it is an embedded template + * @param int $index The index if it is an embedded template * * @return string The template class name */ @@ -311,7 +311,7 @@ class Twig_Environment * Loads a template by name. * * @param string $name The template name - * @param integer $index The index if it is an embedded template + * @param int $index The index if it is an embedded template * * @return Twig_TemplateInterface A template instance representing the given template name * @@ -355,7 +355,7 @@ class Twig_Environment * @param string $name The template name * @param timestamp $time The last modification time of the cached template * - * @return Boolean true if the template is fresh, false otherwise + * @return bool true if the template is fresh, false otherwise */ public function isTemplateFresh($name, $time) { @@ -626,7 +626,7 @@ class Twig_Environment * * @param string $name The extension name * - * @return Boolean Whether the extension is registered or not + * @return bool Whether the extension is registered or not */ public function hasExtension($name) { diff --git a/core/vendor/twig/twig/lib/Twig/Error.php b/core/vendor/twig/twig/lib/Twig/Error.php index 914b3ed30eb..5b253dd752b 100644 --- a/core/vendor/twig/twig/lib/Twig/Error.php +++ b/core/vendor/twig/twig/lib/Twig/Error.php @@ -51,7 +51,7 @@ class Twig_Error extends Exception * By default, automatic guessing is enabled. * * @param string $message The error message - * @param integer $lineno The template line where the error occurred + * @param int $lineno The template line where the error occurred * @param string $filename The template file name where the error occurred * @param Exception $previous The previous exception */ @@ -111,7 +111,7 @@ class Twig_Error extends Exception /** * Gets the template line where the error occurred. * - * @return integer The template line + * @return int The template line */ public function getTemplateLine() { @@ -121,7 +121,7 @@ class Twig_Error extends Exception /** * Sets the template line where the error occurred. * - * @param integer $lineno The template line + * @param int $lineno The template line */ public function setTemplateLine($lineno) { @@ -229,6 +229,8 @@ class Twig_Error extends Exception while ($e = array_pop($exceptions)) { $traces = $e->getTrace(); + array_unshift($traces, array('file' => $e->getFile(), 'line' => $e->getLine())); + while ($trace = array_shift($traces)) { if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) { continue; diff --git a/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php b/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php index da05a54eeb1..48df9e1a3be 100644 --- a/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php +++ b/core/vendor/twig/twig/lib/Twig/ExistsLoaderInterface.php @@ -13,7 +13,8 @@ * Adds an exists() method for loaders. * * @author Florin Patan - * @deprecated since 1.12 (to be removed in 2.0) + * + * @deprecated since 1.12 (to be removed in 3.0) */ interface Twig_ExistsLoaderInterface { @@ -22,7 +23,7 @@ interface Twig_ExistsLoaderInterface * * @param string $name The name of the template to check if we can load * - * @return Boolean If the template source code is handled by this loader or not + * @return bool If the template source code is handled by this loader or not */ public function exists($name); } diff --git a/core/vendor/twig/twig/lib/Twig/ExpressionParser.php b/core/vendor/twig/twig/lib/Twig/ExpressionParser.php index 25f47a15681..f685bad8ec7 100644 --- a/core/vendor/twig/twig/lib/Twig/ExpressionParser.php +++ b/core/vendor/twig/twig/lib/Twig/ExpressionParser.php @@ -318,7 +318,7 @@ class Twig_ExpressionParser throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes)', $line, $this->parser->getFilename()); } - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_Template::ANY_CALL, $line); + return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line); default: if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { $arguments = new Twig_Node_Expression_Array(array(), $line); @@ -451,8 +451,8 @@ class Twig_ExpressionParser /** * Parses arguments. * - * @param Boolean $namedArguments Whether to allow named arguments or not - * @param Boolean $definition Whether we are parsing arguments for a function definition + * @param bool $namedArguments Whether to allow named arguments or not + * @param bool $definition Whether we are parsing arguments for a function definition */ public function parseArguments($namedArguments = false, $definition = false) { diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Core.php b/core/vendor/twig/twig/lib/Twig/Extension/Core.php index 922b5ea9641..e71d741d256 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Core.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Core.php @@ -95,7 +95,7 @@ class Twig_Extension_Core extends Twig_Extension /** * Sets the default format to be used by the number_format filter. * - * @param integer $decimal The number of decimal places to use. + * @param int $decimal The number of decimal places to use. * @param string $decimalPoint The character(s) to use for the decimal point. * @param string $thousandSep The character(s) to use for the thousands separator. */ @@ -173,7 +173,7 @@ class Twig_Extension_Core extends Twig_Extension // array helpers new Twig_SimpleFilter('join', 'twig_join_filter'), - new Twig_SimpleFilter('split', 'twig_split_filter'), + new Twig_SimpleFilter('split', 'twig_split_filter', array('needs_environment' => true)), new Twig_SimpleFilter('sort', 'twig_sort_filter'), new Twig_SimpleFilter('merge', 'twig_array_merge'), new Twig_SimpleFilter('batch', 'twig_array_batch'), @@ -298,8 +298,8 @@ class Twig_Extension_Core extends Twig_Extension public function parseTestExpression(Twig_Parser $parser, Twig_NodeInterface $node) { $stream = $parser->getStream(); - $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); - $class = $this->getTestNodeClass($parser, $name, $node->getLine()); + $name = $this->getTestName($parser, $node->getLine()); + $class = $this->getTestNodeClass($parser, $name); $arguments = null; if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { $arguments = $parser->getExpressionParser()->parseArguments(true); @@ -308,33 +308,41 @@ class Twig_Extension_Core extends Twig_Extension return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine()); } - protected function getTestNodeClass(Twig_Parser $parser, $name, $line) + protected function getTestName(Twig_Parser $parser, $line) { + $stream = $parser->getStream(); + $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue(); $env = $parser->getEnvironment(); $testMap = $env->getTests(); - $testName = null; + if (isset($testMap[$name])) { - $testName = $name; - } elseif ($parser->getStream()->test(Twig_Token::NAME_TYPE)) { + return $name; + } + + if ($stream->test(Twig_Token::NAME_TYPE)) { // try 2-words tests $name = $name.' '.$parser->getCurrentToken()->getValue(); if (isset($testMap[$name])) { $parser->getStream()->next(); - $testName = $name; + return $name; } } - if (null === $testName) { - $message = sprintf('The test "%s" does not exist', $name); - if ($alternatives = $env->computeAlternatives($name, array_keys($env->getTests()))) { - $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); - } - - throw new Twig_Error_Syntax($message, $line, $parser->getFilename()); + $message = sprintf('The test "%s" does not exist', $name); + if ($alternatives = $env->computeAlternatives($name, array_keys($testMap))) { + $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); } + throw new Twig_Error_Syntax($message, $line, $parser->getFilename()); + } + + protected function getTestNodeClass(Twig_Parser $parser, $name) + { + $env = $parser->getEnvironment(); + $testMap = $env->getTests(); + if ($testMap[$name] instanceof Twig_SimpleTest) { return $testMap[$name]->getNodeClass(); } @@ -357,7 +365,7 @@ class Twig_Extension_Core extends Twig_Extension * Cycles over a value. * * @param ArrayAccess|array $values An array or an ArrayAccess instance - * @param integer $position The cycle position + * @param int $position The cycle position * * @return string The next value in the cycle */ @@ -377,7 +385,7 @@ function twig_cycle($values, $position) * - a random integer between 0 and the integer parameter * * @param Twig_Environment $env A Twig_Environment instance - * @param Traversable|array|integer|string $values The values to pick a random item from + * @param Traversable|array|int|string $values The values to pick a random item from * * @throws Twig_Error_Runtime When $values is an empty array (does not apply to an empty string which is returned as is). * @@ -436,10 +444,10 @@ function twig_random(Twig_Environment $env, $values = null) * {{ post.published_at|date("m/d/Y") }} * * - * @param Twig_Environment $env A Twig_Environment instance - * @param DateTime|DateInterval|string $date A date - * @param string $format A format - * @param DateTimeZone|string $timezone A timezone + * @param Twig_Environment $env A Twig_Environment instance + * @param DateTime|DateTimeInterface|DateInterval|string $date A date + * @param string|null $format The target format, null to use the default + * @param DateTimeZone|string|null|false $timezone The target timezone, null to use the default, false to leave unchanged * * @return string The formatted date */ @@ -473,9 +481,12 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $ function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) { $date = twig_date_converter($env, $date, false); - $date->modify($modifier); + $resultDate = $date->modify($modifier); - return $date; + // This is a hack to ensure PHP 5.2 support and support for DateTimeImmutable + // DateTime::modify does not return the modified DateTime object < 5.3.0 + // and DateTimeImmutable does not modify $date. + return null === $resultDate ? $date : $resultDate; } /** @@ -487,32 +498,32 @@ function twig_date_modify_filter(Twig_Environment $env, $date, $modifier) * {% endif %} * * - * @param Twig_Environment $env A Twig_Environment instance - * @param DateTime|string $date A date - * @param DateTimeZone|string $timezone A timezone + * @param Twig_Environment $env A Twig_Environment instance + * @param DateTime|DateTimeInterface|string|null $date A date + * @param DateTimeZone|string|null|false $timezone The target timezone, null to use the default, false to leave unchanged * * @return DateTime A DateTime instance */ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = null) { // determine the timezone - if (!$timezone) { - $defaultTimezone = $env->getExtension('core')->getTimezone(); - } elseif (!$timezone instanceof DateTimeZone) { - $defaultTimezone = new DateTimeZone($timezone); - } else { - $defaultTimezone = $timezone; + if (false !== $timezone) { + if (null === $timezone) { + $timezone = $env->getExtension('core')->getTimezone(); + } elseif (!$timezone instanceof DateTimeZone) { + $timezone = new DateTimeZone($timezone); + } } // immutable dates if ($date instanceof DateTimeImmutable) { - return false !== $timezone ? $date->setTimezone($defaultTimezone) : $date; + return false !== $timezone ? $date->setTimezone($timezone) : $date; } if ($date instanceof DateTime || $date instanceof DateTimeInterface) { $date = clone $date; if (false !== $timezone) { - $date->setTimezone($defaultTimezone); + $date->setTimezone($timezone); } return $date; @@ -523,9 +534,9 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu $date = '@'.$date; } - $date = new DateTime($date, $defaultTimezone); + $date = new DateTime($date, $env->getExtension('core')->getTimezone()); if (false !== $timezone) { - $date->setTimezone($defaultTimezone); + $date->setTimezone($timezone); } return $date; @@ -534,11 +545,11 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu /** * Rounds a number. * - * @param integer|float $value The value to round - * @param integer|float $precision The rounding precision + * @param int|float $value The value to round + * @param int|float $precision The rounding precision * @param string $method The method to use for rounding * - * @return integer|float The rounded number + * @return int|float The rounded number */ function twig_round($value, $precision = 0, $method = 'common') { @@ -562,7 +573,7 @@ function twig_round($value, $precision = 0, $method = 'common') * * @param Twig_Environment $env A Twig_Environment instance * @param mixed $number A float/int/string of the number to format - * @param integer $decimal The number of decimal points to display. + * @param int $decimal The number of decimal points to display. * @param string $decimalPoint The character(s) to use for the decimal point. * @param string $thousandSep The character(s) to use for the thousands separator. * @@ -587,24 +598,23 @@ function twig_number_format_filter(Twig_Environment $env, $number, $decimal = nu } /** - * URL encodes a string as a path segment or an array as a query string. + * URL encodes (RFC 3986) a string as a path segment or an array as a query string. * * @param string|array $url A URL or an array of query parameters - * @param Boolean $raw true to use rawurlencode() instead of urlencode * * @return string The URL encoded value */ -function twig_urlencode_filter($url, $raw = false) +function twig_urlencode_filter($url) { if (is_array($url)) { + if (defined('PHP_QUERY_RFC3986')) { + return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + } + return http_build_query($url, '', '&'); } - if ($raw) { - return rawurlencode($url); - } - - return urlencode($url); + return rawurlencode($url); } if (version_compare(PHP_VERSION, '5.3.0', '<')) { @@ -612,7 +622,7 @@ if (version_compare(PHP_VERSION, '5.3.0', '<')) { * JSON encodes a variable. * * @param mixed $value The value to encode. - * @param integer $options Not used on PHP 5.2.x + * @param int $options Not used on PHP 5.2.x * * @return mixed The JSON encoded value */ @@ -631,7 +641,7 @@ if (version_compare(PHP_VERSION, '5.3.0', '<')) { * JSON encodes a variable. * * @param mixed $value The value to encode. - * @param integer $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT + * @param int $options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT * * @return mixed The JSON encoded value */ @@ -673,7 +683,7 @@ function _twig_markup2string(&$value) function twig_array_merge($arr1, $arr2) { if (!is_array($arr1) || !is_array($arr2)) { - throw new Twig_Error_Runtime('The merge filter only works with arrays or hashes.'); + throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or hashes; %s and %s given.', gettype($arr1), gettype($arr2))); } return array_merge($arr1, $arr2); @@ -684,16 +694,24 @@ function twig_array_merge($arr1, $arr2) * * @param Twig_Environment $env A Twig_Environment instance * @param mixed $item A variable - * @param integer $start Start of the slice - * @param integer $length Size of the slice - * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array) + * @param int $start Start of the slice + * @param int $length Size of the slice + * @param bool $preserveKeys Whether to preserve key or not (when the input is an array) * * @return mixed The sliced variable */ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false) { if ($item instanceof Traversable) { - $item = iterator_to_array($item, false); + if ($item instanceof IteratorAggregate) { + $item = $item->getIterator(); + } + + if ($start >= 0 && $length >= 0) { + return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys); + } + + $item = iterator_to_array($item, $preserveKeys); } if (is_array($item)) { @@ -703,10 +721,10 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese $item = (string) $item; if (function_exists('mb_get_info') && null !== $charset = $env->getCharset()) { - return mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); + return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); } - return null === $length ? substr($item, $start) : substr($item, $start, $length); + return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length)); } /** @@ -785,17 +803,35 @@ function twig_join_filter($value, $glue = '') * * @param string $value A string * @param string $delimiter The delimiter - * @param integer $limit The limit + * @param int $limit The limit * * @return array The split string as an array */ -function twig_split_filter($value, $delimiter, $limit = null) +function twig_split_filter(Twig_Environment $env, $value, $delimiter, $limit = null) { - if (empty($delimiter)) { + if (!empty($delimiter)) { + return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); + } + + if (!function_exists('mb_get_info') || null === $charset = $env->getCharset()) { return str_split($value, null === $limit ? 1 : $limit); } - return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); + if ($limit <= 1) { + return preg_split('/(? true, 'UTF-8' => true); } else { $htmlspecialcharsCharsets = array( @@ -1192,7 +1228,7 @@ if (function_exists('mb_get_info')) { * @param Twig_Environment $env A Twig_Environment instance * @param mixed $thing A variable * - * @return integer The length of the value + * @return int The length of the value */ function twig_length_filter(Twig_Environment $env, $thing) { @@ -1276,7 +1312,7 @@ else { * @param Twig_Environment $env A Twig_Environment instance * @param mixed $thing A variable * - * @return integer The length of the value + * @return int The length of the value */ function twig_length_filter(Twig_Environment $env, $thing) { @@ -1332,7 +1368,7 @@ function twig_ensure_traversable($seq) * * @param mixed $value A variable * - * @return Boolean true if the value is empty, false otherwise + * @return bool true if the value is empty, false otherwise */ function twig_test_empty($value) { @@ -1355,7 +1391,7 @@ function twig_test_empty($value) * * @param mixed $value A variable * - * @return Boolean true if the value is traversable + * @return bool true if the value is traversable */ function twig_test_iterable($value) { @@ -1367,9 +1403,9 @@ function twig_test_iterable($value) * * @param string|array $template The template to render or an array of templates to try consecutively * @param array $variables The variables to pass to the template - * @param Boolean $with_context Whether to pass the current context variables or not - * @param Boolean $ignore_missing Whether to ignore missing templates or not - * @param Boolean $sandboxed Whether to sandbox the template or not + * @param bool $with_context Whether to pass the current context variables or not + * @param bool $ignore_missing Whether to ignore missing templates or not + * @param bool $sandboxed Whether to sandbox the template or not * * @return string The rendered template */ @@ -1434,7 +1470,7 @@ function twig_constant($constant, $object = null) * Batches item. * * @param array $items An array of items - * @param integer $size The size of the batch + * @param int $size The size of the batch * @param mixed $fill A value used to fill missing items * * @return array diff --git a/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php b/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php index c59609f61df..c58259c6abc 100644 --- a/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/Extension/Sandbox.php @@ -93,7 +93,7 @@ class Twig_Extension_Sandbox extends Twig_Extension public function ensureToStringAllowed($obj) { - if (is_object($obj)) { + if ($this->isSandboxed() && is_object($obj)) { $this->policy->checkMethodAllowed($obj, '__toString'); } diff --git a/core/vendor/twig/twig/lib/Twig/LexerInterface.php b/core/vendor/twig/twig/lib/Twig/LexerInterface.php index dd51caeee7b..24a9478700e 100644 --- a/core/vendor/twig/twig/lib/Twig/LexerInterface.php +++ b/core/vendor/twig/twig/lib/Twig/LexerInterface.php @@ -13,7 +13,8 @@ * Interface implemented by lexer classes. * * @author Fabien Potencier - * @deprecated since 1.12 (to be removed in 2.0) + * + * @deprecated since 1.12 (to be removed in 3.0) */ interface Twig_LexerInterface { diff --git a/core/vendor/twig/twig/lib/Twig/Loader/Array.php b/core/vendor/twig/twig/lib/Twig/Loader/Array.php index ac561048578..436edd816a0 100644 --- a/core/vendor/twig/twig/lib/Twig/Loader/Array.php +++ b/core/vendor/twig/twig/lib/Twig/Loader/Array.php @@ -17,6 +17,8 @@ * source code of the template). If you don't want to see your cache grows out of * control, you need to take care of clearing the old cache file by yourself. * + * This loader should only be used for unit testing. + * * @author Fabien Potencier */ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface diff --git a/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php b/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php index 2d6170c3602..d0ae1cc1d77 100644 --- a/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php +++ b/core/vendor/twig/twig/lib/Twig/Loader/Filesystem.php @@ -176,16 +176,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI $this->validateName($name); - $namespace = self::MAIN_NAMESPACE; - $shortname = $name; - if (isset($name[0]) && '@' == $name[0]) { - if (false === $pos = strpos($name, '/')) { - throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); - } - - $namespace = substr($name, 1, $pos - 1); - $shortname = substr($name, $pos + 1); - } + list($namespace, $shortname) = $this->parseName($name); if (!isset($this->paths[$namespace])) { throw new Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); @@ -200,6 +191,22 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]))); } + protected function parseName($name, $default = self::MAIN_NAMESPACE) + { + if (isset($name[0]) && '@' == $name[0]) { + if (false === $pos = strpos($name, '/')) { + throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + } + + $namespace = substr($name, 1, $pos - 1); + $shortname = substr($name, $pos + 1); + + return array($namespace, $shortname); + } + + return array($default, $name); + } + protected function normalizeName($name) { return preg_replace('#/{2,}#', '/', strtr((string) $name, '\\', '/')); diff --git a/core/vendor/twig/twig/lib/Twig/Loader/String.php b/core/vendor/twig/twig/lib/Twig/Loader/String.php index 8ad9856cc08..2099c09c9ae 100644 --- a/core/vendor/twig/twig/lib/Twig/Loader/String.php +++ b/core/vendor/twig/twig/lib/Twig/Loader/String.php @@ -12,9 +12,7 @@ /** * Loads a template from a string. * - * This loader should only be used for unit testing as it has many limitations - * (for instance, the include or extends tag does not make any sense for a string - * loader). + * This loader should NEVER be used. It only exists for Twig internal purposes. * * When using this loader with a cache mechanism, you should know that a new cache * key is generated each time a template content "changes" (the cache key being the diff --git a/core/vendor/twig/twig/lib/Twig/LoaderInterface.php b/core/vendor/twig/twig/lib/Twig/LoaderInterface.php index 927786d1af4..4405291fff3 100644 --- a/core/vendor/twig/twig/lib/Twig/LoaderInterface.php +++ b/core/vendor/twig/twig/lib/Twig/LoaderInterface.php @@ -44,7 +44,7 @@ interface Twig_LoaderInterface * @param string $name The template name * @param timestamp $time The last modification time of the cached template * - * @return Boolean true if the template is fresh, false otherwise + * @return bool true if the template is fresh, false otherwise * * @throws Twig_Error_Loader When $name is not found */ diff --git a/core/vendor/twig/twig/lib/Twig/Node.php b/core/vendor/twig/twig/lib/Twig/Node.php index 931b4635a94..20af544981d 100644 --- a/core/vendor/twig/twig/lib/Twig/Node.php +++ b/core/vendor/twig/twig/lib/Twig/Node.php @@ -30,7 +30,7 @@ class Twig_Node implements Twig_NodeInterface * * @param array $nodes An array of named nodes * @param array $attributes An array of attributes (should not be nodes) - * @param integer $lineno The line number + * @param int $lineno The line number * @param string $tag The tag name associated with the Node */ public function __construct(array $nodes = array(), array $attributes = array(), $lineno = 0, $tag = null) @@ -69,6 +69,9 @@ class Twig_Node implements Twig_NodeInterface return implode("\n", $repr); } + /** + * @deprecated since 1.16.1 (to be removed in 2.0) + */ public function toXml($asDom = false) { $dom = new DOMDocument('1.0', 'UTF-8'); @@ -121,7 +124,7 @@ class Twig_Node implements Twig_NodeInterface * * @param string The attribute name * - * @return Boolean true if the attribute is defined, false otherwise + * @return bool true if the attribute is defined, false otherwise */ public function hasAttribute($name) { @@ -170,7 +173,7 @@ class Twig_Node implements Twig_NodeInterface * * @param string The node name * - * @return Boolean true if the node with the given name exists, false otherwise + * @return bool true if the node with the given name exists, false otherwise */ public function hasNode($name) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php b/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php index 8f190e0bd85..fcabf903382 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php +++ b/core/vendor/twig/twig/lib/Twig/Node/AutoEscape.php @@ -30,7 +30,7 @@ class Twig_Node_AutoEscape extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Block.php b/core/vendor/twig/twig/lib/Twig/Node/Block.php index 50eb67ed8c5..989e4a0ca8b 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Block.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Block.php @@ -25,7 +25,7 @@ class Twig_Node_Block extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/BlockReference.php b/core/vendor/twig/twig/lib/Twig/Node/BlockReference.php index 013e369ebe8..a05ea045bff 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/BlockReference.php +++ b/core/vendor/twig/twig/lib/Twig/Node/BlockReference.php @@ -25,7 +25,7 @@ class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInter /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Do.php b/core/vendor/twig/twig/lib/Twig/Node/Do.php index c528066b29f..9981bc16ba3 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Do.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Do.php @@ -24,7 +24,7 @@ class Twig_Node_Do extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php index 1da785fe427..6cf7ca14451 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Array.php @@ -63,7 +63,7 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php index 2ddea78cf05..4d5dbdb903e 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/AssignName.php @@ -15,7 +15,7 @@ class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php index 9dd5de2c83a..5c383d1552b 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary.php @@ -19,7 +19,7 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php index 5de6c72d21e..93b3b96f0ec 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/EndsWith.php @@ -12,14 +12,14 @@ class Twig_Node_Expression_Binary_EndsWith extends Twig_Node_Expression_Binary { public function compile(Twig_Compiler $compiler) { + $left = $compiler->getVarName(); + $right = $compiler->getVarName(); $compiler - ->raw('(0 === substr_compare(') + ->raw(sprintf('(is_string($%s = ', $left)) ->subcompile($this->getNode('left')) - ->raw(', ') + ->raw(sprintf(') && is_string($%s = ', $right)) ->subcompile($this->getNode('right')) - ->raw(', -strlen(') - ->subcompile($this->getNode('right')) - ->raw(')))') + ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right)) ; } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php index 7fbd0556fca..d3518b558a2 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/FloorDiv.php @@ -13,7 +13,7 @@ class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php index 788f9377aea..1d485b61c1a 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/In.php @@ -13,7 +13,7 @@ class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php index f347b7b6e82..8f215f1c114 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/NotIn.php @@ -13,7 +13,7 @@ class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php index b2c59040500..6cd3a217ce0 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Power.php @@ -13,7 +13,7 @@ class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php index bea4f2a6070..fc102fed305 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/Range.php @@ -13,7 +13,7 @@ class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php index eb8c107cb1a..d2e30d66e50 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Binary/StartsWith.php @@ -12,12 +12,14 @@ class Twig_Node_Expression_Binary_StartsWith extends Twig_Node_Expression_Binary { public function compile(Twig_Compiler $compiler) { + $left = $compiler->getVarName(); + $right = $compiler->getVarName(); $compiler - ->raw('(0 === strpos(') + ->raw(sprintf('(is_string($%s = ', $left)) ->subcompile($this->getNode('left')) - ->raw(', ') + ->raw(sprintf(') && is_string($%s = ', $right)) ->subcompile($this->getNode('right')) - ->raw('))') + ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right)) ; } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php index 647196eb5b8..4ddb2cf4409 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/BlockReference.php @@ -25,7 +25,7 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php index d019696e9a8..912b837a9f1 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Call.php @@ -12,10 +12,8 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression { protected function compileCallable(Twig_Compiler $compiler) { - $callable = $this->getAttribute('callable'); - $closingParenthesis = false; - if ($callable) { + if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) { if (is_string($callable)) { $compiler->raw($callable); } elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php index 00ac6701f41..db06abb0adf 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/ExtensionReference.php @@ -24,7 +24,7 @@ class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php index 55d9fcc3204..6ce61111cf2 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/GetAttr.php @@ -11,7 +11,7 @@ */ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression { - public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression_Array $arguments, $type, $lineno) + public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression $arguments = null, $type, $lineno) { parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno); } @@ -32,20 +32,30 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression $compiler->raw(', ')->subcompile($this->getNode('attribute')); - if (count($this->getNode('arguments')) || Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { - $compiler->raw(', ')->subcompile($this->getNode('arguments')); + // only generate optional arguments when needed (to make generated code more readable) + $needFourth = $this->getAttribute('ignore_strict_check'); + $needThird = $needFourth || $this->getAttribute('is_defined_test'); + $needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type'); + $needFirst = $needSecond || null !== $this->getNode('arguments'); - if (Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { - $compiler->raw(', ')->repr($this->getAttribute('type')); + if ($needFirst) { + if (null !== $this->getNode('arguments')) { + $compiler->raw(', ')->subcompile($this->getNode('arguments')); + } else { + $compiler->raw(', array()'); } + } - if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { - $compiler->raw(', '.($this->getAttribute('is_defined_test') ? 'true' : 'false')); - } + if ($needSecond) { + $compiler->raw(', ')->repr($this->getAttribute('type')); + } - if ($this->getAttribute('ignore_strict_check')) { - $compiler->raw(', '.($this->getAttribute('ignore_strict_check') ? 'true' : 'false')); - } + if ($needThird) { + $compiler->raw(', ')->repr($this->getAttribute('is_defined_test')); + } + + if ($needFourth) { + $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check')); } $compiler->raw(')'); diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php index dcf618c04a6..a22ce038634 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Parent.php @@ -25,7 +25,7 @@ class Twig_Node_Expression_Parent extends Twig_Node_Expression /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php b/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php index 0aceb5302cb..d5bed234a8e 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Expression/Test/Divisibleby.php @@ -13,7 +13,7 @@ * Checks if a variable is divisible by a number. * *
- *  {% if loop.index is divisibleby(3) %}
+ *  {% if loop.index is divisible by(3) %}
  * 
* * @author Fabien Potencier diff --git a/core/vendor/twig/twig/lib/Twig/Node/Flush.php b/core/vendor/twig/twig/lib/Twig/Node/Flush.php index 0467ddcefc5..20d6aab43ee 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Flush.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Flush.php @@ -24,7 +24,7 @@ class Twig_Node_Flush extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/For.php b/core/vendor/twig/twig/lib/Twig/Node/For.php index d1ff371da1b..c54a23cc98f 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/For.php +++ b/core/vendor/twig/twig/lib/Twig/Node/For.php @@ -33,7 +33,7 @@ class Twig_Node_For extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/ForLoop.php b/core/vendor/twig/twig/lib/Twig/Node/ForLoop.php index b8841583d97..d330283e782 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/ForLoop.php +++ b/core/vendor/twig/twig/lib/Twig/Node/ForLoop.php @@ -24,7 +24,7 @@ class Twig_Node_ForLoop extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/If.php b/core/vendor/twig/twig/lib/Twig/Node/If.php index b42d1075550..980274e5cd0 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/If.php +++ b/core/vendor/twig/twig/lib/Twig/Node/If.php @@ -25,7 +25,7 @@ class Twig_Node_If extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Import.php b/core/vendor/twig/twig/lib/Twig/Node/Import.php index 99efc0911c3..230665541a7 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Import.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Import.php @@ -24,7 +24,7 @@ class Twig_Node_Import extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Include.php b/core/vendor/twig/twig/lib/Twig/Node/Include.php index ed4a3751250..06548884a13 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Include.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Include.php @@ -19,13 +19,13 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface { public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) { - parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (Boolean) $only, 'ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag); + parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing), $lineno, $tag); } /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { @@ -60,40 +60,26 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface protected function addGetTemplate(Twig_Compiler $compiler) { - if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) { - $compiler - ->write("\$this->env->loadTemplate(") - ->subcompile($this->getNode('expr')) - ->raw(")") - ; - } else { - $compiler - ->write("\$template = \$this->env->resolveTemplate(") - ->subcompile($this->getNode('expr')) - ->raw(");\n") - ->write('$template') - ; - } + $method = $this->getNode('expr') instanceof Twig_Node_Expression_Constant ? 'loadTemplate' : 'resolveTemplate'; + $compiler + ->write(sprintf('$this->env->%s(', $method)) + ->subcompile($this->getNode('expr')) + ->raw(')') + ; } protected function addTemplateArguments(Twig_Compiler $compiler) { - if (false === $this->getAttribute('only')) { - if (null === $this->getNode('variables')) { - $compiler->raw('$context'); - } else { - $compiler - ->raw('array_merge($context, ') - ->subcompile($this->getNode('variables')) - ->raw(')') - ; - } + if (null === $this->getNode('variables')) { + $compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()'); + } elseif (false === $this->getAttribute('only')) { + $compiler + ->raw('array_merge($context, ') + ->subcompile($this->getNode('variables')) + ->raw(')') + ; } else { - if (null === $this->getNode('variables')) { - $compiler->raw('array()'); - } else { - $compiler->subcompile($this->getNode('variables')); - } + $compiler->subcompile($this->getNode('variables')); } } } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Macro.php b/core/vendor/twig/twig/lib/Twig/Node/Macro.php index 89910618b87..ab7e8d25a2c 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Macro.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Macro.php @@ -24,7 +24,7 @@ class Twig_Node_Macro extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { @@ -37,7 +37,7 @@ class Twig_Node_Macro extends Twig_Node $pos = 0; foreach ($this->getNode('arguments') as $name => $default) { $compiler - ->raw('$_'.$name.' = ') + ->raw('$__'.$name.'__ = ') ->subcompile($default) ; @@ -64,7 +64,7 @@ class Twig_Node_Macro extends Twig_Node $compiler ->write('') ->string($name) - ->raw(' => $_'.$name) + ->raw(' => $__'.$name.'__') ->raw(",\n") ; } diff --git a/core/vendor/twig/twig/lib/Twig/Node/Module.php b/core/vendor/twig/twig/lib/Twig/Node/Module.php index 3f801757221..9f66b28d50f 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Module.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Module.php @@ -31,7 +31,7 @@ class Twig_Node_Module extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Print.php b/core/vendor/twig/twig/lib/Twig/Node/Print.php index b0c41d1d921..42635361a60 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Print.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Print.php @@ -25,7 +25,7 @@ class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php b/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php index 8cf3ed44f76..8ca772bcdfe 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Sandbox.php @@ -24,7 +24,7 @@ class Twig_Node_Sandbox extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/SandboxedModule.php b/core/vendor/twig/twig/lib/Twig/Node/SandboxedModule.php index be1f5daa732..410332cc365 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/SandboxedModule.php +++ b/core/vendor/twig/twig/lib/Twig/Node/SandboxedModule.php @@ -23,7 +23,7 @@ class Twig_Node_SandboxedModule extends Twig_Node_Module public function __construct(Twig_Node_Module $node, array $usedFilters, array $usedTags, array $usedFunctions) { - parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag()); + parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename')); $this->setAttribute('index', $node->getAttribute('index')); @@ -43,17 +43,53 @@ class Twig_Node_SandboxedModule extends Twig_Node_Module { parent::compileDisplayFooter($compiler); + $tags = $filters = $functions = array(); + foreach (array('tags', 'filters', 'functions') as $type) { + foreach ($this->{'used'.ucfirst($type)} as $name => $node) { + if ($node instanceof Twig_Node) { + ${$type}[$name] = $node->getLine(); + } else { + ${$type}[$node] = null; + } + } + } + $compiler ->write("protected function checkSecurity()\n", "{\n") ->indent() + ->write("\$tags = ")->repr(array_filter($tags))->raw(";\n") + ->write("\$filters = ")->repr(array_filter($filters))->raw(";\n") + ->write("\$functions = ")->repr(array_filter($functions))->raw(";\n\n") + ->write("try {\n") + ->indent() ->write("\$this->env->getExtension('sandbox')->checkSecurity(\n") ->indent() - ->write(!$this->usedTags ? "array(),\n" : "array('".implode('\', \'', $this->usedTags)."'),\n") - ->write(!$this->usedFilters ? "array(),\n" : "array('".implode('\', \'', $this->usedFilters)."'),\n") - ->write(!$this->usedFunctions ? "array()\n" : "array('".implode('\', \'', $this->usedFunctions)."')\n") + ->write(!$tags ? "array(),\n" : "array('".implode("', '", array_keys($tags))."'),\n") + ->write(!$filters ? "array(),\n" : "array('".implode("', '", array_keys($filters))."'),\n") + ->write(!$functions ? "array()\n" : "array('".implode("', '", array_keys($functions))."')\n") ->outdent() ->write(");\n") ->outdent() + ->write("} catch (Twig_Sandbox_SecurityError \$e) {\n") + ->indent() + ->write("\$e->setTemplateFile(\$this->getTemplateName());\n\n") + ->write("if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") + ->outdent() + ->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") + ->indent() + ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") + ->outdent() + ->write("}\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("}\n") + ->outdent() ->write("}\n\n") ; } diff --git a/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php b/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php index 73dfaa9639a..91872ccccdc 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php +++ b/core/vendor/twig/twig/lib/Twig/Node/SandboxedPrint.php @@ -29,7 +29,7 @@ class Twig_Node_SandboxedPrint extends Twig_Node_Print /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Set.php b/core/vendor/twig/twig/lib/Twig/Node/Set.php index 4c9c16ce2fb..407d147342b 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Set.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Set.php @@ -39,7 +39,7 @@ class Twig_Node_Set extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php b/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php index 7555fa0f182..1478c59acb2 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Spaceless.php @@ -26,7 +26,7 @@ class Twig_Node_Spaceless extends Twig_Node /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/Node/Text.php b/core/vendor/twig/twig/lib/Twig/Node/Text.php index 21bdcea1485..6863604e50c 100644 --- a/core/vendor/twig/twig/lib/Twig/Node/Text.php +++ b/core/vendor/twig/twig/lib/Twig/Node/Text.php @@ -25,7 +25,7 @@ class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler) { diff --git a/core/vendor/twig/twig/lib/Twig/NodeInterface.php b/core/vendor/twig/twig/lib/Twig/NodeInterface.php index f0ef725825c..8077349b3c1 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeInterface.php +++ b/core/vendor/twig/twig/lib/Twig/NodeInterface.php @@ -13,14 +13,15 @@ * Represents a node in the AST. * * @author Fabien Potencier - * @deprecated since 1.12 (to be removed in 2.0) + * + * @deprecated since 1.12 (to be removed in 3.0) */ interface Twig_NodeInterface extends Countable, IteratorAggregate { /** * Compiles the node to PHP. * - * @param Twig_Compiler A Twig_Compiler instance + * @param Twig_Compiler $compiler A Twig_Compiler instance */ public function compile(Twig_Compiler $compiler); diff --git a/core/vendor/twig/twig/lib/Twig/NodeTraverser.php b/core/vendor/twig/twig/lib/Twig/NodeTraverser.php index aacaf2938cd..8178a55c0d0 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeTraverser.php +++ b/core/vendor/twig/twig/lib/Twig/NodeTraverser.php @@ -70,7 +70,7 @@ class Twig_NodeTraverser protected function traverseForVisitor(Twig_NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) { if (null === $node) { - return null; + return; } $node = $visitor->enterNode($node, $this->env); diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php index 5bf8eb0c596..3cc3312b5a3 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php @@ -28,6 +28,7 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface const OPTIMIZE_VAR_ACCESS = 8; protected $loops = array(); + protected $loopsTargets = array(); protected $optimizers; protected $prependedNodes = array(); protected $inABody = false; @@ -35,7 +36,7 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface /** * Constructor. * - * @param integer $optimizers The optimizer mode + * @param int $optimizers The optimizer mode */ public function __construct($optimizers = -1) { @@ -174,6 +175,8 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface // disable the loop variable by default $node->setAttribute('with_loop', false); array_unshift($this->loops, $node); + array_unshift($this->loopsTargets, $node->getNode('value_target')->getAttribute('name')); + array_unshift($this->loopsTargets, $node->getNode('key_target')->getAttribute('name')); } elseif (!$this->loops) { // we are outside a loop return; @@ -183,9 +186,15 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface // the loop variable is referenced for the current loop elseif ($node instanceof Twig_Node_Expression_Name && 'loop' === $node->getAttribute('name')) { + $node->setAttribute('always_defined', true); $this->addLoopToCurrent(); } + // optimize access to loop targets + elseif ($node instanceof Twig_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) { + $node->setAttribute('always_defined', true); + } + // block reference elseif ($node instanceof Twig_Node_BlockReference || $node instanceof Twig_Node_Expression_BlockReference) { $this->addLoopToCurrent(); @@ -221,6 +230,8 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface { if ($node instanceof Twig_Node_For) { array_shift($this->loops); + array_shift($this->loopsTargets); + array_shift($this->loopsTargets); } } diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php index fb27045baaf..e5e3ff631d6 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitor/Sandbox.php @@ -40,18 +40,18 @@ class Twig_NodeVisitor_Sandbox implements Twig_NodeVisitorInterface return $node; } elseif ($this->inAModule) { // look for tags - if ($node->getNodeTag()) { - $this->tags[] = $node->getNodeTag(); + if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) { + $this->tags[$node->getNodeTag()] = $node; } // look for filters - if ($node instanceof Twig_Node_Expression_Filter) { - $this->filters[] = $node->getNode('filter')->getAttribute('value'); + if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { + $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; } // look for functions - if ($node instanceof Twig_Node_Expression_Function) { - $this->functions[] = $node->getAttribute('name'); + if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) { + $this->functions[$node->getAttribute('name')] = $node; } // wrap print to check __toString() calls @@ -76,7 +76,7 @@ class Twig_NodeVisitor_Sandbox implements Twig_NodeVisitorInterface if ($node instanceof Twig_Node_Module) { $this->inAModule = false; - return new Twig_Node_SandboxedModule($node, array_unique($this->filters), array_unique($this->tags), array_unique($this->functions)); + return new Twig_Node_SandboxedModule($node, $this->filters, $this->tags, $this->functions); } return $node; diff --git a/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php b/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php index f33c13fc226..608adedb023 100644 --- a/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php +++ b/core/vendor/twig/twig/lib/Twig/NodeVisitorInterface.php @@ -41,7 +41,7 @@ interface Twig_NodeVisitorInterface * * Priority should be between -10 and 10 (0 is the default). * - * @return integer The priority level + * @return int The priority level */ public function getPriority(); } diff --git a/core/vendor/twig/twig/lib/Twig/ParserInterface.php b/core/vendor/twig/twig/lib/Twig/ParserInterface.php index bfe60a36131..8e7cc0a85ce 100644 --- a/core/vendor/twig/twig/lib/Twig/ParserInterface.php +++ b/core/vendor/twig/twig/lib/Twig/ParserInterface.php @@ -13,7 +13,8 @@ * Interface implemented by parser classes. * * @author Fabien Potencier - * @deprecated since 1.12 (to be removed in 2.0) + * + * @deprecated since 1.12 (to be removed in 3.0) */ interface Twig_ParserInterface { diff --git a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php new file mode 100644 index 00000000000..99faba9dd37 --- /dev/null +++ b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php @@ -0,0 +1,31 @@ + + */ +class Twig_Sandbox_SecurityNotAllowedFilterError extends Twig_Sandbox_SecurityError +{ + private $filterName; + + public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->filterName = $functionName; + } + + public function getFilterName() + { + return $this->filterName; + } +} diff --git a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php new file mode 100644 index 00000000000..05cf488af89 --- /dev/null +++ b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php @@ -0,0 +1,31 @@ + + */ +class Twig_Sandbox_SecurityNotAllowedFunctionError extends Twig_Sandbox_SecurityError +{ + private $functionName; + + public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->functionName = $functionName; + } + + public function getFunctionName() + { + return $this->functionName; + } +} diff --git a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php new file mode 100644 index 00000000000..b3bb5e8e2b8 --- /dev/null +++ b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityNotAllowedTagError.php @@ -0,0 +1,31 @@ + + */ +class Twig_Sandbox_SecurityNotAllowedTagError extends Twig_Sandbox_SecurityError +{ + private $tagName; + + public function __construct($message, $tagName, $lineno = -1, $filename = null, Exception $previous = null) + { + parent::__construct($message, $lineno, $filename, $previous); + $this->tagName = $tagName; + } + + public function getTagName() + { + return $this->tagName; + } +} diff --git a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php index 66ee233200b..c4dd03dffe3 100644 --- a/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php +++ b/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php @@ -63,19 +63,19 @@ class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterfac { foreach ($tags as $tag) { if (!in_array($tag, $this->allowedTags)) { - throw new Twig_Sandbox_SecurityError(sprintf('Tag "%s" is not allowed.', $tag)); + throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); } } foreach ($filters as $filter) { if (!in_array($filter, $this->allowedFilters)) { - throw new Twig_Sandbox_SecurityError(sprintf('Filter "%s" is not allowed.', $filter)); + throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); } } foreach ($functions as $function) { if (!in_array($function, $this->allowedFunctions)) { - throw new Twig_Sandbox_SecurityError(sprintf('Function "%s" is not allowed.', $function)); + throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); } } } diff --git a/core/vendor/twig/twig/lib/Twig/Template.php b/core/vendor/twig/twig/lib/Twig/Template.php index b13df5d358b..63910dacc09 100644 --- a/core/vendor/twig/twig/lib/Twig/Template.php +++ b/core/vendor/twig/twig/lib/Twig/Template.php @@ -105,9 +105,9 @@ abstract class Twig_Template implements Twig_TemplateInterface $name = (string) $name; if (isset($this->traits[$name])) { - $this->traits[$name][0]->displayBlock($name, $context, $blocks); + $this->traits[$name][0]->displayBlock($name, $context, $blocks, false); } elseif (false !== $parent = $this->getParent($context)) { - $parent->displayBlock($name, $context, $blocks); + $parent->displayBlock($name, $context, $blocks, false); } else { throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block', $name), -1, $this->getTemplateName()); } @@ -119,18 +119,18 @@ abstract class Twig_Template implements Twig_TemplateInterface * This method is for internal use only and should never be called * directly. * - * @param string $name The block name to display - * @param array $context The context - * @param array $blocks The current set of blocks + * @param string $name The block name to display + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks */ - public function displayBlock($name, array $context, array $blocks = array()) + public function displayBlock($name, array $context, array $blocks = array(), $useBlocks = true) { $name = (string) $name; - if (isset($blocks[$name])) { + if ($useBlocks && isset($blocks[$name])) { $template = $blocks[$name][0]; $block = $blocks[$name][1]; - unset($blocks[$name]); } elseif (isset($this->blocks[$name])) { $template = $this->blocks[$name][0]; $block = $this->blocks[$name][1]; @@ -148,7 +148,7 @@ abstract class Twig_Template implements Twig_TemplateInterface throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getTemplateName(), $e); } } elseif (false !== $parent = $this->getParent($context)) { - $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks)); + $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); } } @@ -178,16 +178,17 @@ abstract class Twig_Template implements Twig_TemplateInterface * This method is for internal use only and should never be called * directly. * - * @param string $name The block name to render - * @param array $context The context - * @param array $blocks The current set of blocks + * @param string $name The block name to render + * @param array $context The context + * @param array $blocks The current set of blocks + * @param bool $useBlocks Whether to use the current set of blocks * * @return string The rendered block */ - public function renderBlock($name, array $context, array $blocks = array()) + public function renderBlock($name, array $context, array $blocks = array(), $useBlocks = true) { ob_start(); - $this->displayBlock($name, $context, $blocks); + $this->displayBlock($name, $context, $blocks, $useBlocks); return ob_get_clean(); } @@ -207,7 +208,7 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @param string $name The block name * - * @return Boolean true if the block exists, false otherwise + * @return bool true if the block exists, false otherwise */ public function hasBlock($name) { @@ -249,7 +250,7 @@ abstract class Twig_Template implements Twig_TemplateInterface */ public function display(array $context, array $blocks = array()) { - $this->displayWithErrorHandling($this->env->mergeGlobals($context), $blocks); + $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } /** @@ -315,7 +316,7 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @param array $context The context * @param string $item The variable to return from the context - * @param Boolean $ignoreStrictCheck Whether to ignore the strict variable check or not + * @param bool $ignoreStrictCheck Whether to ignore the strict variable check or not * * @return The content of the context variable * @@ -325,7 +326,7 @@ abstract class Twig_Template implements Twig_TemplateInterface { if (!array_key_exists($item, $context)) { if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; + return; } throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), -1, $this->getTemplateName()); @@ -341,8 +342,8 @@ abstract class Twig_Template implements Twig_TemplateInterface * @param mixed $item The item to get from the array or object * @param array $arguments An array of arguments to pass if the item is an object method * @param string $type The type of attribute (@see Twig_Template constants) - * @param Boolean $isDefinedTest Whether this is only a defined check - * @param Boolean $ignoreStrictCheck Whether to ignore the strict attribute check or not + * @param bool $isDefinedTest Whether this is only a defined check + * @param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not * * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true * @@ -370,7 +371,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; + return; } if ($object instanceof ArrayAccess) { @@ -378,7 +379,11 @@ abstract class Twig_Template implements Twig_TemplateInterface } elseif (is_object($object)) { $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object)); } elseif (is_array($object)) { - $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + if (empty($object)) { + $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); + } else { + $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + } } elseif (Twig_Template::ARRAY_CALL === $type) { $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } else { @@ -395,14 +400,12 @@ abstract class Twig_Template implements Twig_TemplateInterface } if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; + return; } throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); } - $class = get_class($object); - // object property if (Twig_Template::METHOD_CALL !== $type) { if (isset($object->$item) || array_key_exists((string) $item, $object)) { @@ -418,6 +421,8 @@ abstract class Twig_Template implements Twig_TemplateInterface } } + $class = get_class($object); + // object method if (!isset(self::$cache[$class]['methods'])) { self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object))); @@ -440,7 +445,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { - return null; + return; } throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName()); @@ -460,7 +465,7 @@ abstract class Twig_Template implements Twig_TemplateInterface $ret = call_user_func_array(array($object, $method), $arguments); } catch (BadMethodCallException $e) { if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { - return null; + return; } throw $e; } diff --git a/core/vendor/twig/twig/lib/Twig/TemplateInterface.php b/core/vendor/twig/twig/lib/Twig/TemplateInterface.php index 879f503ec1d..d178832eb75 100644 --- a/core/vendor/twig/twig/lib/Twig/TemplateInterface.php +++ b/core/vendor/twig/twig/lib/Twig/TemplateInterface.php @@ -13,7 +13,8 @@ * Interface implemented by all compiled templates. * * @author Fabien Potencier - * @deprecated since 1.12 (to be removed in 2.0) + * + * @deprecated since 1.12 (to be removed in 3.0) */ interface Twig_TemplateInterface { diff --git a/core/vendor/twig/twig/lib/Twig/Token.php b/core/vendor/twig/twig/lib/Twig/Token.php index 4411d7b3475..599f9f565d1 100644 --- a/core/vendor/twig/twig/lib/Twig/Token.php +++ b/core/vendor/twig/twig/lib/Twig/Token.php @@ -38,9 +38,9 @@ class Twig_Token /** * Constructor. * - * @param integer $type The type of the token + * @param int $type The type of the token * @param string $value The token value - * @param integer $lineno The line position in the source + * @param int $lineno The line position in the source */ public function __construct($type, $value, $lineno) { @@ -67,10 +67,10 @@ class Twig_Token * * type and value (or array of possible values) * * just value (or array of possible values) (NAME_TYPE is used as type) * - * @param array|integer $type The type to test + * @param array|int $type The type to test * @param array|string|null $values The token value * - * @return Boolean + * @return bool */ public function test($type, $values = null) { @@ -89,7 +89,7 @@ class Twig_Token /** * Gets the line. * - * @return integer The source line + * @return int The source line */ public function getLine() { @@ -99,7 +99,7 @@ class Twig_Token /** * Gets the token type. * - * @return integer The token type + * @return int The token type */ public function getType() { @@ -119,8 +119,8 @@ class Twig_Token /** * Returns the constant representation (internal) of a given type. * - * @param integer $type The type as an integer - * @param Boolean $short Whether to return a short representation or not + * @param int $type The type as an integer + * @param bool $short Whether to return a short representation or not * * @return string The string representation */ @@ -176,7 +176,7 @@ class Twig_Token /** * Returns the english representation of a given type. * - * @param integer $type The type as an integer + * @param int $type The type as an integer * * @return string The string representation */ diff --git a/core/vendor/twig/twig/lib/Twig/TokenStream.php b/core/vendor/twig/twig/lib/Twig/TokenStream.php index 22f0428fae9..44440daedd2 100644 --- a/core/vendor/twig/twig/lib/Twig/TokenStream.php +++ b/core/vendor/twig/twig/lib/Twig/TokenStream.php @@ -101,7 +101,7 @@ class Twig_TokenStream /** * Looks at the next token. * - * @param integer $number + * @param int $number * * @return Twig_Token */ @@ -117,7 +117,7 @@ class Twig_TokenStream /** * Tests the current token * - * @return Boolean + * @return bool */ public function test($primary, $secondary = null) { @@ -127,7 +127,7 @@ class Twig_TokenStream /** * Checks if end of stream was reached * - * @return Boolean + * @return bool */ public function isEOF() { diff --git a/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php b/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php index a5fc87887fb..b791e57f5c6 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/EnvironmentTest.php @@ -48,7 +48,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase // globals can be added after calling getGlobals $twig = new Twig_Environment(new Twig_Loader_String()); $twig->addGlobal('foo', 'foo'); - $globals = $twig->getGlobals(); + $twig->getGlobals(); $twig->addGlobal('foo', 'bar'); $globals = $twig->getGlobals(); $this->assertEquals('bar', $globals['foo']); @@ -65,7 +65,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase // globals can be modified after extensions init $twig = new Twig_Environment(new Twig_Loader_String()); $twig->addGlobal('foo', 'foo'); - $globals = $twig->getGlobals(); + $twig->getGlobals(); $twig->getFunctions(); $twig->addGlobal('foo', 'bar'); $globals = $twig->getGlobals(); @@ -74,7 +74,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase // globals can be modified after extensions and runtime init $twig = new Twig_Environment(new Twig_Loader_String()); $twig->addGlobal('foo', 'foo'); - $globals = $twig->getGlobals(); + $twig->getGlobals(); $twig->getFunctions(); $twig->initRuntime(); $twig->addGlobal('foo', 'bar'); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php b/core/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php index 5f3da18d5e9..b3b1cb0b994 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Extension/CoreTest.php @@ -130,6 +130,24 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase { twig_escape_filter(new Twig_Environment(), 'foo', 'bar'); } + + public function testTwigFirst() + { + $twig = new Twig_Environment(); + $this->assertEquals('a', twig_first($twig, 'abc')); + $this->assertEquals(1, twig_first($twig, array(1, 2, 3))); + $this->assertSame('', twig_first($twig, null)); + $this->assertSame('', twig_first($twig, '')); + } + + public function testTwigLast() + { + $twig = new Twig_Environment(); + $this->assertEquals('c', twig_last($twig, 'abc')); + $this->assertEquals(3, twig_last($twig, array(1, 2, 3))); + $this->assertSame('', twig_last($twig, null)); + $this->assertSame('', twig_last($twig, '')); + } } function foo_escaper_for_test(Twig_Environment $env, $string, $charset) diff --git a/core/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php b/core/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php index e4746cb30b7..fee35a0ab50 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php @@ -33,13 +33,13 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase '1_basic9' => '{{ obj.foobar }}{{ obj.fooBar }}', '1_basic' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}', '1_layout' => '{% block content %}{% endblock %}', - '1_child' => '{% extends "1_layout" %}{% block content %}{{ "a"|json_encode }}{% endblock %}', + '1_child' => "{% extends \"1_layout\" %}\n{% block content %}\n{{ \"a\"|json_encode }}\n{% endblock %}", ); } /** * @expectedException Twig_Sandbox_SecurityError - * @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child". + * @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child" at line 3. */ public function testSandboxWithInheritance() { @@ -111,6 +111,11 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allow some methods'); $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); + $twig = $this->getEnvironment(false, array(), self::$templates); + FooObject::reset(); + $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled'); + $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array('upper')); $this->assertEquals('FABIEN', $twig->loadTemplate('1_basic2')->render(self::$params), 'Sandbox allow some filters'); diff --git a/core/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php b/core/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php index 8efc948f4db..36cdd337aef 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/FileCachingTest.php @@ -32,7 +32,7 @@ class Twig_Tests_FileCachingTest extends PHPUnit_Framework_TestCase public function testWritingCacheFiles() { $name = 'This is just text.'; - $template = $this->env->loadTemplate($name); + $this->env->loadTemplate($name); $cacheFileName = $this->env->getCacheFilename($name); $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.'); @@ -42,7 +42,7 @@ class Twig_Tests_FileCachingTest extends PHPUnit_Framework_TestCase public function testClearingCacheFiles() { $name = 'I will be deleted.'; - $template = $this->env->loadTemplate($name); + $this->env->loadTemplate($name); $cacheFileName = $this->env->getCacheFilename($name); $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.'); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test index 026bd52c66d..6679fbe132d 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test @@ -6,4 +6,4 @@ Exception for an undefined trait {% block bar %} {% endblock %} --EXCEPTION-- -Twig_Error_Runtime: Block "foobar" is not defined in trait "foo" in "index.twig". +Twig_Error_Runtime: Block "foobar" is not defined in trait "foo" in "index.twig" at line 2. diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test index 7b56b76108e..74fe6cabb7d 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/bitwise.test @@ -4,7 +4,7 @@ Twig supports bitwise operations {{ 1 b-and 5 }} {{ 1 b-or 5 }} {{ 1 b-xor 5 }} -{{ (1 and 0 b-or 0) is sameas(1 and (0 b-or 0)) ? 'ok' : 'ko' }} +{{ (1 and 0 b-or 0) is same as(1 and (0 b-or 0)) ? 'ok' : 'ko' }} --DATA-- return array() --EXPECT-- diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test index 14ee5e4d3a3..238dd279039 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/divisibleby.test @@ -1,8 +1,6 @@ --TEST-- Twig supports the "divisible by" operator --TEMPLATE-- -{{ 8 is divisibleby(2) ? 'OK' }} -{{ 8 is not divisibleby(3) ? 'OK' }} {{ 8 is divisible by(2) ? 'OK' }} {{ 8 is not divisible by(3) ? 'OK' }} {{ 8 is divisible by (2) ? 'OK' }} @@ -17,5 +15,3 @@ OK OK OK OK -OK -OK diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test index d259d1189d1..9ad5e5e8ebf 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/ends_with.test @@ -4,9 +4,23 @@ Twig supports the "ends with" operator {{ 'foo' ends with 'o' ? 'OK' : 'KO' }} {{ not ('foo' ends with 'f') ? 'OK' : 'KO' }} {{ not ('foo' ends with 'foowaytoolong') ? 'OK' : 'KO' }} +{{ 'foo' ends with '' ? 'OK' : 'KO' }} +{{ '1' ends with true ? 'OK' : 'KO' }} +{{ 1 ends with true ? 'OK' : 'KO' }} +{{ 0 ends with false ? 'OK' : 'KO' }} +{{ '' ends with false ? 'OK' : 'KO' }} +{{ false ends with false ? 'OK' : 'KO' }} +{{ false ends with '' ? 'OK' : 'KO' }} --DATA-- return array() --EXPECT-- OK OK OK +OK +KO +KO +KO +KO +KO +KO diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test index 9e8514fbe95..601201deb38 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/sameas.test @@ -1,8 +1,8 @@ --TEST-- Twig supports the "same as" operator --TEMPLATE-- -{{ 1 is sameas(1) ? 'OK' }} -{{ 1 is not sameas(true) ? 'OK' }} +{{ 1 is same as(1) ? 'OK' }} +{{ 1 is not same as(true) ? 'OK' }} {{ 1 is same as(1) ? 'OK' }} {{ 1 is not same as(true) ? 'OK' }} {{ 1 is same as (1) ? 'OK' }} diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test index 1ae4f86efce..75d331e90a8 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/expressions/starts_with.test @@ -7,6 +7,11 @@ Twig supports the "starts with" operator {{ 'foo' starts with 'f' ? 'OK' : 'KO' }} {{ 'foo' starts with 'f' ? 'OK' : 'KO' }} +{{ 'foo' starts with '' ? 'OK' : 'KO' }} +{{ '1' starts with true ? 'OK' : 'KO' }} +{{ '' starts with false ? 'OK' : 'KO' }} +{{ 'a' starts with false ? 'OK' : 'KO' }} +{{ false starts with '' ? 'OK' : 'KO' }} --DATA-- return array() --EXPECT-- @@ -15,3 +20,8 @@ OK OK OK OK +OK +KO +KO +KO +KO diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.php b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test similarity index 95% rename from core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.php rename to core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test index 52de39cb767..e2ec4beb215 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/batch_float.test @@ -15,17 +15,15 @@ return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'))
a
b
c
+
d
-
d
e
f
-
-
g
h
-
i
+
i
j
diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test index d40bb04adf0..d17e5e2f072 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date.test @@ -31,6 +31,13 @@ {{ date6|date('e', false) }} {{ date7|date }} +{{ date7|date(timezone='Europe/Paris') }} +{{ date7|date(timezone='Asia/Hong_Kong') }} +{{ date7|date(timezone=false) }} +{{ date7|date(timezone='Indian/Mauritius') }} + +{{ '2010-01-28 15:00:00'|date(timezone="Europe/Paris") }} +{{ '2010-01-28 15:00:00'|date(timezone="Asia/Hong_Kong") }} --DATA-- date_default_timezone_set('Europe/Paris'); return array( @@ -40,7 +47,7 @@ return array( 'date4' => 1286199900, // DateTime::createFromFormat('Y-m-d H:i', '2010-10-04 13:45', new DateTimeZone('UTC'))->getTimestamp() -- A unixtimestamp is always GMT 'date5' => -189291360, // DateTime::createFromFormat('Y-m-d H:i', '1964-01-02 03:04', new DateTimeZone('UTC'))->getTimestamp(), 'date6' => new DateTime('2010-10-04 13:45', new DateTimeZone('America/New_York')), - 'date7' => '2010-01-28T15:00:00+05:00', + 'date7' => '2010-01-28T15:00:00+04:00', 'timezone1' => new DateTimeZone('America/New_York'), ) --EXPECT-- @@ -73,4 +80,11 @@ January 2, 1964 04:04 Europe/Paris America/New_York -January 28, 2010 11:00 +January 28, 2010 12:00 +January 28, 2010 12:00 +January 28, 2010 19:00 +January 28, 2010 15:00 +January 28, 2010 15:00 + +January 28, 2010 15:00 +January 28, 2010 22:00 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test index b89ceb30942..4e183256209 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/date_immutable.test @@ -8,6 +8,7 @@ version_compare(phpversion(), '5.5.0', '>=') {{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }} {{ date1|date('d/m/Y H:i:s', timezone1) }} {{ date1|date('d/m/Y H:i:s') }} +{{ date1|date_modify('+1 hour')|date('d/m/Y H:i:s') }} {{ date2|date('d/m/Y H:i:s P', 'Europe/Paris') }} {{ date2|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }} @@ -27,6 +28,7 @@ October 4, 2010 13:45 04/10/2010 19:45:00 04/10/2010 07:45:00 04/10/2010 13:45:00 +04/10/2010 14:45:00 04/10/2010 19:45:00 +02:00 05/10/2010 01:45:00 +08:00 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test index 0e4404b1c76..b8d1d66f5ed 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/default.test @@ -2,42 +2,42 @@ "default" filter --TEMPLATE-- Variable: -{{ definedVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ zeroVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ emptyVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nullVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ undefinedVar |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ definedVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ zeroVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ emptyVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ nullVar |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ undefinedVar |default('default') is same as('default') ? 'ok' : 'ko' }} Array access: -{{ nested.definedVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ nested['definedVar'] |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ nested.zeroVar |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ nested.emptyVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nested.nullVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nested.undefinedVar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nested['undefinedVar'] |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ undefinedVar.foo |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ nested.definedVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested['definedVar'] |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested.zeroVar |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ nested.emptyVar |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' }} +{{ undefinedVar.foo |default('default') is same as('default') ? 'ok' : 'ko' }} Plain values: -{{ 'defined' |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ 0 |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ '' |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ null |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ 'defined' |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ 0 |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ '' |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ null |default('default') is same as('default') ? 'ok' : 'ko' }} Precedence: {{ 'o' ~ nullVar |default('k') }} {{ 'o' ~ nested.nullVar |default('k') }} Object methods: -{{ object.foo |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ object.undefinedMethod |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ object.getFoo() |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ object.getFoo('a') |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ object.undefinedMethod() |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ object.undefinedMethod('a') |default('default') is sameas('default') ? 'ok' : 'ko' }} +{{ object.foo |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.undefinedMethod |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ object.getFoo() |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.getFoo('a') |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.undefinedMethod() |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ object.undefinedMethod('a') |default('default') is same as('default') ? 'ok' : 'ko' }} Deep nested: -{{ nested.undefinedVar.foo.bar |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ nested.definedArray.0 |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ nested['definedArray'][0] |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ object.self.foo |default('default') is sameas('default') ? 'ko' : 'ok' }} -{{ object.self.undefinedMethod |default('default') is sameas('default') ? 'ok' : 'ko' }} -{{ object.undefinedMethod.self |default('default') is sameas('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' }} +{{ object.self.foo |default('default') is same as('default') ? 'ko' : 'ok' }} +{{ object.self.undefinedMethod |default('default') is same as('default') ? 'ok' : 'ko' }} +{{ object.undefinedMethod.self |default('default') is same as('default') ? 'ok' : 'ko' }} --DATA-- return array( 'definedVar' => 'defined', diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test index 90f49271f21..aa54645c38d 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/first.test @@ -6,6 +6,7 @@ {{ '1234'|first }} {{ arr|first }} {{ 'Ä€é'|first }} +{{ ''|first }} --DATA-- return array('arr' => new ArrayObject(array(1, 2, 3, 4))) --EXPECT-- diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test index 018fdad8954..1b8031ee840 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/last.test @@ -6,6 +6,7 @@ {{ '1234'|last }} {{ arr|last }} {{ 'Ä€é'|last }} +{{ ''|last }} --DATA-- return array('arr' => new ArrayObject(array(1, 2, 3, 4))) --EXPECT-- diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test index b37ad6514ae..fb36a4ebbd0 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/slice.test @@ -19,6 +19,9 @@ {{ '1234'|slice(1) }} {{ '1234'[1:] }} {{ '1234'[:1] }} + +{{ arr|slice(3)|join('') }} +{{ arr[2:]|join('') }} --DATA-- return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4))) --EXPECT-- @@ -40,3 +43,6 @@ bc 234 234 1 + +4 +34 \ No newline at end of file diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test index ce8ec9cec64..a093ed79b5a 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split.test @@ -5,6 +5,7 @@ {{ foo|split(',')|join('-') }} {{ foo|split(',', 3)|join('-') }} {{ baz|split('')|join('-') }} +{{ baz|split('', 1)|join('-') }} {{ baz|split('', 2)|join('-') }} {{ foo|split(',', -2)|join('-') }} --DATA-- @@ -14,5 +15,6 @@ one-two-three-four-five one-two-three-four-five one-two-three,four,five 1-2-3-4-5 +1-2-3-4-5 12-34-5 one-two-three \ No newline at end of file diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test new file mode 100644 index 00000000000..305e162feac --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/split_utf8.test @@ -0,0 +1,24 @@ +--TEST-- +"split" filter +--CONDITION-- +function_exists('mb_get_info') +--TEMPLATE-- +{{ "é"|split('', 10)|join('-') }} +{{ foo|split(',')|join('-') }} +{{ foo|split(',', 1)|join('-') }} +{{ foo|split(',', 2)|join('-') }} +{{ foo|split(',', 3)|join('-') }} +{{ baz|split('')|join('-') }} +{{ baz|split('', 1)|join('-') }} +{{ baz|split('', 2)|join('-') }} +--DATA-- +return array('foo' => 'Ä,é,Äほ', 'baz' => 'éÄßごa',) +--EXPECT-- +é +Ä-é-Äほ +Ä,é,Äほ +Ä-é,Äほ +Ä-é-Äほ +é-Ä-ß-ご-a +é-Ä-ß-ご-a +éÄ-ßご-a \ No newline at end of file diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test index de956e7a30b..8726159db06 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode.test @@ -1,12 +1,16 @@ --TEST-- "url_encode" filter +--CONDITION-- +defined('PHP_QUERY_RFC3986') --TEMPLATE-- {{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }} {{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }} {{ {}|url_encode|default("default") }} +{{ 'spéßi%le%c0d@dspa ce'|url_encode }} --DATA-- return array() --EXPECT-- -foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa+ce= -foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa+ce= +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= default +sp%C3%A9%C3%9Fi%25le%25c0d%40dspa%20ce diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test new file mode 100644 index 00000000000..11800e9c0b4 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/filters/urlencode_deprecated.test @@ -0,0 +1,16 @@ +--TEST-- +"url_encode" filter for PHP < 5.4 and HHVM +--CONDITION-- +defined('PHP_QUERY_RFC3986') +--TEMPLATE-- +{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode }} +{{ {foo: "bar", number: 3, "spéßi%l": "e%c0d@d", "spa ce": ""}|url_encode|raw }} +{{ {}|url_encode|default("default") }} +{{ 'spéßi%le%c0d@dspa ce'|url_encode }} +--DATA-- +return array() +--EXPECT-- +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +foo=bar&number=3&sp%C3%A9%C3%9Fi%25l=e%25c0d%40d&spa%20ce= +default +sp%C3%A9%C3%9Fi%25le%25c0d%40dspa%20ce diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test index 472b74d1c4a..71b2038aa94 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/attribute.test @@ -4,13 +4,15 @@ {{ attribute(obj, method) }} {{ attribute(array, item) }} {{ attribute(obj, "bar", ["a", "b"]) }} +{{ attribute(obj, "bar", arguments) }} {{ attribute(obj, method) is defined ? 'ok' : 'ko' }} {{ attribute(obj, nonmethod) is defined ? 'ok' : 'ko' }} --DATA-- -return array('obj' => new TwigTestFoo(), 'method' => 'foo', 'array' => array('foo' => 'bar'), 'item' => 'foo', 'nonmethod' => 'xxx') +return array('obj' => new TwigTestFoo(), 'method' => 'foo', 'array' => array('foo' => 'bar'), 'item' => 'foo', 'nonmethod' => 'xxx', 'arguments' => array('a', 'b')) --EXPECT-- foo bar bar_a-b +bar_a-b ok ko diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test index 788a2ab0bdd..7b9ccaca81f 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/include/sandbox.test @@ -3,8 +3,11 @@ --TEMPLATE-- {{ include("foo.twig", sandboxed = true) }} --TEMPLATE(foo.twig)-- + + +{{ foo|e }} {{ foo|e }} --DATA-- return array() --EXCEPTION-- -Twig_Sandbox_SecurityError: Filter "e" is not allowed in "index.twig" at line 2. +Twig_Sandbox_SecurityNotAllowedFilterError: Filter "e" is not allowed in "foo.twig" at line 4. diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test new file mode 100644 index 00000000000..f39712da8fe --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/functions/recursive_block_with_inheritance.test @@ -0,0 +1,21 @@ +--TEST-- +"block" function recursively called in a parent template +--TEMPLATE-- +{% extends "ordered_menu.twig" %} +{% block label %}"{{ parent() }}"{% endblock %} +{% block list %}{% set class = 'b' %}{{ parent() }}{% endblock %} +--TEMPLATE(ordered_menu.twig)-- +{% extends "menu.twig" %} +{% block list %}{% set class = class|default('a') %}
    {{ block('children') }}
{% endblock %} +--TEMPLATE(menu.twig)-- +{% extends "base.twig" %} +{% 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 %} +--TEMPLATE(base.twig)-- +{{ block('list') }} +--DATA-- +return array('item' => array('1', '2', array('3.1', array('3.2.1', '3.2.2'), '3.4'))) +--EXPECT-- +
    1. "1"
    2. "2"
      1. "3.1"
        1. "3.2.1"
        2. "3.2.2"
      2. "3.4"
    diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test new file mode 100644 index 00000000000..df485783a79 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/combined_debug_info.test @@ -0,0 +1,15 @@ +--TEST-- +Exception with bad line number +--TEMPLATE-- +{% block content %} + {{ foo }} + {{ include("foo") }} +{% endblock %} +index +--TEMPLATE(foo)-- +foo +{{ foo.bar }} +--DATA-- +return array('foo' => 'foo'); +--EXCEPTION-- +Twig_Error_Runtime: Impossible to access an attribute ("bar") on a string variable ("foo") in "foo" at line 3 diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test new file mode 100644 index 00000000000..269a30571d6 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/regression/multi_word_tests.test @@ -0,0 +1,10 @@ +--TEST-- +Twig allows multi-word tests without a custom node class +--TEMPLATE-- +{{ 'foo' is multi word ? 'yes' : 'no' }} +{{ 'foo bar' is multi word ? 'yes' : 'no' }} +--DATA-- +return array() +--EXPECT-- +no +yes diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test new file mode 100644 index 00000000000..9a81499ab3c --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr.test @@ -0,0 +1,32 @@ +--TEST-- +block_expr +--TEMPLATE-- +{% extends "base.twig" %} + +{% block element -%} + Element: + {{- parent() -}} +{% endblock %} +--TEMPLATE(base.twig)-- +{% spaceless %} +{% block element -%} +
    + {%- if item.children is defined %} + {%- for item in item.children %} + {{- block('element') -}} + {% endfor %} + {%- endif -%} +
    +{%- endblock %} +{% endspaceless %} +--DATA-- +return array( + 'item' => array( + 'children' => array( + null, + null, + ) + ) +) +--EXPECT-- +Element:
    Element:
    Element:
    diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test new file mode 100644 index 00000000000..3e868c0da7d --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/inheritance/block_expr2.test @@ -0,0 +1,34 @@ +--TEST-- +block_expr2 +--TEMPLATE-- +{% extends "base2.twig" %} + +{% block element -%} + Element: + {{- parent() -}} +{% endblock %} +--TEMPLATE(base2.twig)-- +{% extends "base.twig" %} +--TEMPLATE(base.twig)-- +{% spaceless %} +{% block element -%} +
    + {%- if item.children is defined %} + {%- for item in item.children %} + {{- block('element') -}} + {% endfor %} + {%- endif -%} +
    +{%- endblock %} +{% endspaceless %} +--DATA-- +return array( + 'item' => array( + 'children' => array( + null, + null, + ) + ) +) +--EXPECT-- +Element:
    Element:
    Element:
    diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test new file mode 100644 index 00000000000..5679462819d --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/macro/super_globals.test @@ -0,0 +1,14 @@ +--TEST-- +Super globals as macro arguments +--TEMPLATE-- +{% import _self as macros %} + +{{ macros.foo('foo') }} + +{% macro foo(GET) %} + {{ GET }} +{% endmacro %} +--DATA-- +return array() +--EXPECT-- +foo diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test new file mode 100644 index 00000000000..6368b08de02 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance.test @@ -0,0 +1,25 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "parent.twig" %} + +{{ block('container') }} +--TEMPLATE(parent.twig)-- +{% use "ancestor.twig" %} + +{% block sub_container %} +
    overriden sub_container
    +{% endblock %} +--TEMPLATE(ancestor.twig)-- +{% block container %} +
    {{ block('sub_container') }}
    +{% endblock %} + +{% block sub_container %} +
    sub_container
    +{% endblock %} +--DATA-- +return array() +--EXPECT-- +
    overriden sub_container
    +
    diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test new file mode 100644 index 00000000000..114e3015e93 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/inheritance2.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "ancestor.twig" %} +{% use "parent.twig" %} + +{{ block('container') }} +--TEMPLATE(parent.twig)-- +{% block sub_container %} +
    overriden sub_container
    +{% endblock %} +--TEMPLATE(ancestor.twig)-- +{% block container %} +
    {{ block('sub_container') }}
    +{% endblock %} + +{% block sub_container %} +
    sub_container
    +{% endblock %} +--DATA-- +return array() +--EXPECT-- +
    overriden sub_container
    +
    diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test new file mode 100644 index 00000000000..59db23d955f --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig' with foobar as base_base_foobar %} +{% block foobar %} + {{- block('base_base_foobar') -}} + Content of block (second override) +{% endblock foobar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' with foobar as base_foobar %} +{% block foobar %} + {{- block('base_foobar') -}} + Content of block (first override) +{% endblock foobar %} +--TEMPLATE(file1.html.twig)-- +{% block foobar -%} + Content of block +{% endblock foobar %} +--DATA-- +return array() +--EXPECT-- +Content of block +Content of block (first override) +Content of block (second override) diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test new file mode 100644 index 00000000000..d3f302df042 --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block2.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig'%} +{% block foobar %} + {{- parent() -}} + Content of block (second override) +{% endblock foobar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' %} +{% block foobar %} + {{- parent() -}} + Content of block (first override) +{% endblock foobar %} +--TEMPLATE(file1.html.twig)-- +{% block foobar -%} + Content of block +{% endblock foobar %} +--DATA-- +return array() +--EXPECT-- +Content of block +Content of block (first override) +Content of block (second override) diff --git a/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test new file mode 100644 index 00000000000..95b55a4690e --- /dev/null +++ b/core/vendor/twig/twig/test/Twig/Tests/Fixtures/tags/use/parent_block3.test @@ -0,0 +1,38 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig' %} +{% use 'file1.html.twig' with foo %} +{% block foo %} + {{- parent() -}} + Content of foo (second override) +{% endblock foo %} +{% block bar %} + {{- parent() -}} + Content of bar (second override) +{% endblock bar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' %} +{% block foo %} + {{- parent() -}} + Content of foo (first override) +{% endblock foo %} +{% block bar %} + {{- parent() -}} + Content of bar (first override) +{% endblock bar %} +--TEMPLATE(file1.html.twig)-- +{% block foo -%} + Content of foo +{% endblock foo %} +{% block bar -%} + Content of bar +{% endblock bar %} +--DATA-- +return array() +--EXPECT-- +Content of foo +Content of foo (first override) +Content of foo (second override) +Content of bar +Content of bar (second override) diff --git a/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php b/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php index ea00b0245d9..70f9b80654b 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/IntegrationTest.php @@ -157,6 +157,13 @@ class TwigTestExtension extends Twig_Extension ); } + public function getTests() + { + return array( + new Twig_SimpleTest('multi word', array($this, 'is_multi_word')), + ); + } + public function §Filter($value) { return "§{$value}§"; @@ -210,6 +217,11 @@ class TwigTestExtension extends Twig_Extension return '
    '; } + public function is_multi_word($value) + { + return false !== strpos($value, ' '); + } + public function getName() { return 'integration_test'; diff --git a/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php b/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php index ab104f4b0c6..c4d70831264 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php @@ -46,7 +46,6 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $stream = $lexer->tokenize($template); $count = 0; - $tokens = array(); while (!$stream->isEOF()) { $token = $stream->next(); if ($type === $token->getType()) { @@ -114,7 +113,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $template = '{% raw %}'.str_repeat('*', 100000).'{% endraw %}'; $lexer = new Twig_Lexer(new Twig_Environment()); - $stream = $lexer->tokenize($template); + $lexer->tokenize($template); // should not throw an exception } @@ -124,7 +123,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $template = '{{ '.str_repeat('x', 100000).' }}'; $lexer = new Twig_Lexer(new Twig_Environment()); - $stream = $lexer->tokenize($template); + $lexer->tokenize($template); // should not throw an exception } @@ -134,17 +133,13 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $template = '{% '.str_repeat('x', 100000).' %}'; $lexer = new Twig_Lexer(new Twig_Environment()); - $stream = $lexer->tokenize($template); + $lexer->tokenize($template); // should not throw an exception } public function testBigNumbers() { - if ('hiphop' === substr(PHP_VERSION, -6)) { - $this->markTestSkipped('hhvm thinks that the number is actually a T_CONSTANT_ENCAPSED_STRING!'); - } - $template = '{{ 922337203685477580700 }}'; $lexer = new Twig_Lexer(new Twig_Environment()); @@ -216,7 +211,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $template = '{{ "bar #{x" }}'; $lexer = new Twig_Lexer(new Twig_Environment()); - $stream = $lexer->tokenize($template); + $lexer->tokenize($template); } public function testStringWithNestedInterpolations() @@ -281,7 +276,7 @@ bar '; $lexer = new Twig_Lexer(new Twig_Environment()); - $stream = $lexer->tokenize($template); + $lexer->tokenize($template); } /** @@ -300,6 +295,6 @@ bar '; $lexer = new Twig_Lexer(new Twig_Environment()); - $stream = $lexer->tokenize($template); + $lexer->tokenize($template); } } diff --git a/core/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php b/core/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php index 9519bdf4aaf..7de268c652d 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/NativeExtensionTest.php @@ -23,7 +23,7 @@ class Twig_Tests_NativeExtensionTest extends PHPUnit_Framework_TestCase $d2 = new DateTime(); $output = $twig->render('{{ d1.date }}{{ d2.date }}', compact('d1', 'd2')); - if ('hiphop' === substr(PHP_VERSION, -6)) { + if (defined('HHVM_VERSION')) { $this->markTestSkipped('Skip under HHVM as the behavior is not the same as plain PHP (which is an edge case anyway)'); } diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php index 62fb0d35eb7..76cf5c6316c 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -46,7 +46,7 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase $attr = new Twig_Node_Expression_Constant('bar', 1); $args = new Twig_Node_Expression_Array(array(), 1); $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1); - $tests[] = array($node, sprintf('%s%s, "bar")', $this->getAttributeGetter(), $this->getVariableGetter('foo'))); + $tests[] = array($node, sprintf('%s%s, "bar", array())', $this->getAttributeGetter(), $this->getVariableGetter('foo'))); $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); $tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo'))); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php index e8aa326b31e..9afecef85bd 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php @@ -59,8 +59,7 @@ EOF $node = new Twig_Node_Include($expr, null, false, false, 1); $tests[] = array($node, <<env->resolveTemplate(((true) ? ("foo") : ("foo"))); -\$template->display(\$context); +\$this->env->resolveTemplate(((true) ? ("foo") : ("foo")))->display(\$context); EOF ); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php index 4d2f641befb..2a77ac7a657 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/MacroTest.php @@ -46,11 +46,11 @@ class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase return array( array($node, <<env->mergeGlobals(array( - "foo" => \$_foo, - "bar" => \$_bar, + "foo" => \$__foo__, + "bar" => \$__bar__, )); \$blocks = array(); diff --git a/core/vendor/twig/twig/test/Twig/Tests/Node/SandboxedModuleTest.php b/core/vendor/twig/twig/test/Twig/Tests/Node/SandboxedModuleTest.php index 421f2109b83..bb9ffb78240 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/Node/SandboxedModuleTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/Node/SandboxedModuleTest.php @@ -84,11 +84,29 @@ class __TwigTemplate_a2bfbf7dd6ab85666684fe9297f69363a3fc2046d90f22a317d380c1863 protected function checkSecurity() { - \$this->env->getExtension('sandbox')->checkSecurity( - array('upper'), - array('for'), - array('cycle') - ); + \$tags = array(); + \$filters = array(); + \$functions = array(); + + try { + \$this->env->getExtension('sandbox')->checkSecurity( + array('upper'), + array('for'), + array('cycle') + ); + } catch (Twig_Sandbox_SecurityError \$e) { + \$e->setTemplateFile(\$this->getTemplateName()); + + if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) { + \$e->setTemplateLine(\$tags[\$e->getTagName()]); + } elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) { + \$e->setTemplateLine(\$filters[\$e->getFilterName()]); + } elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) { + \$e->setTemplateLine(\$functions[\$e->getFunctionName()]); + } + + throw \$e; + } } public function getTemplateName() @@ -143,11 +161,29 @@ class __TwigTemplate_a2bfbf7dd6ab85666684fe9297f69363a3fc2046d90f22a317d380c1863 protected function checkSecurity() { - \$this->env->getExtension('sandbox')->checkSecurity( - array('upper'), - array('for'), - array('cycle') - ); + \$tags = array(); + \$filters = array(); + \$functions = array(); + + try { + \$this->env->getExtension('sandbox')->checkSecurity( + array('upper'), + array('for'), + array('cycle') + ); + } catch (Twig_Sandbox_SecurityError \$e) { + \$e->setTemplateFile(\$this->getTemplateName()); + + if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) { + \$e->setTemplateLine(\$tags[\$e->getTagName()]); + } elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) { + \$e->setTemplateLine(\$filters[\$e->getFilterName()]); + } elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) { + \$e->setTemplateLine(\$functions[\$e->getFunctionName()]); + } + + throw \$e; + } } public function getTemplateName() diff --git a/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php b/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php index aa8dafd4db2..e2f84eeed78 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/TemplateTest.php @@ -28,6 +28,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $context = array( 'string' => 'foo', + 'empty_array' => array(), 'array' => array('foo' => 'foo'), 'array_access' => new Twig_TemplateArrayAccessObject(), 'magic_exception' => new Twig_TemplateMagicPropertyObjectWithException(), @@ -46,10 +47,12 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase { $tests = array( array('{{ string["a"] }}', 'Impossible to access a key ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ empty_array["a"] }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), array('{{ array["a"] }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ array_access["a"] }}', 'Key "a" in object with ArrayAccess of class "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), array('{{ string.a }}', 'Impossible to access an attribute ("a") on a string variable ("foo") in "%s" at line 1', false), array('{{ string.a() }}', 'Impossible to invoke a method ("a") on a string variable ("foo") in "%s" at line 1', false), + array('{{ empty_array.a }}', 'Key "a" does not exist as the array is empty in "%s" at line 1', false), array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ array_access.a }}', 'Method "a" for object "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), @@ -368,7 +371,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $tests = array_merge($tests, array( array(false, null, 42, 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a integer variable ("42")'), array(false, null, "string", 'a', array(), $anyType, false, 'Impossible to access an attribute ("a") on a string variable ("string")'), - array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" for array with keys "" does not exist'), + array(false, null, array(), 'a', array(), $anyType, false, 'Key "a" does not exist as the array is empty'), )); // add twig_template_get_attributes tests @@ -585,7 +588,6 @@ class Twig_TemplateMethodObject public function getNull() { - return null; } public function isBar() diff --git a/core/vendor/twig/twig/test/Twig/Tests/escapingTest.php b/core/vendor/twig/twig/test/Twig/Tests/escapingTest.php index 34d2a2dbfc0..d581315a008 100644 --- a/core/vendor/twig/twig/test/Twig/Tests/escapingTest.php +++ b/core/vendor/twig/twig/test/Twig/Tests/escapingTest.php @@ -227,7 +227,7 @@ class Twig_Test_EscapingTest extends PHPUnit_Framework_TestCase /** * Convert a Unicode Codepoint to a literal UTF-8 character. * - * @param int Unicode codepoint in hex notation + * @param int $codepoint Unicode codepoint in hex notation * @return string UTF-8 literal string */ protected function codepointToUtf8($codepoint) @@ -301,7 +301,7 @@ class Twig_Test_EscapingTest extends PHPUnit_Framework_TestCase public function testCssEscapingEscapesOwaspRecommendedRanges() { - $immune = array(); // CSS has no exceptions to escaping ranges + // CSS has no exceptions to escaping ranges for ($chr=0; $chr < 0xFF; $chr++) { if ($chr >= 0x30 && $chr <= 0x39 || $chr >= 0x41 && $chr <= 0x5A