From 944a0146366f082d32613942ea0195040dc4c607 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 20 Apr 2012 19:04:30 +0200 Subject: [PATCH] renamed preserve_safety to preserves_safety to be consisten with needs_context and needs_environment --- CHANGELOG | 2 +- lib/Twig/Filter.php | 6 +- lib/Twig/FilterInterface.php | 2 +- lib/Twig/NodeVisitor/SafeAnalysis.php | 2 +- .../autoescape/with_preserve_safety_filters.test | 50 -------------------- .../autoescape/with_preserves_safety_filters.test | 50 ++++++++++++++++++++ test/Twig/Tests/integrationTest.php | 4 +- 7 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 test/Twig/Tests/Fixtures/tags/autoescape/with_preserve_safety_filters.test create mode 100644 test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test diff --git a/CHANGELOG b/CHANGELOG index 4fd5cb7..d85bbdb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ * 1.7.0 (2012-XX-XX) * added an error when defining two blocks with the same name in a template - * added the preserve_safety option for filters + * added the preserves_safety option for filters * fixed a PHP notice when trying to access a key on a non-object/array variable * enhanced error reporting when the template file is an instance of SplFileInfo * added Twig_Environment::mergeGlobals() diff --git a/lib/Twig/Filter.php b/lib/Twig/Filter.php index b5e400d..1a4806c 100644 --- a/lib/Twig/Filter.php +++ b/lib/Twig/Filter.php @@ -26,7 +26,7 @@ abstract class Twig_Filter implements Twig_FilterInterface 'needs_environment' => false, 'needs_context' => false, 'pre_escape' => null, - 'preserve_safety' => null, + 'preserves_safety' => null, ), $options); } @@ -63,9 +63,9 @@ abstract class Twig_Filter implements Twig_FilterInterface return null; } - public function getPreserveSafety() + public function getPreservesSafety() { - return $this->options['preserve_safety']; + return $this->options['preserves_safety']; } public function getPreEscape() diff --git a/lib/Twig/FilterInterface.php b/lib/Twig/FilterInterface.php index 20a29e5..f398026 100644 --- a/lib/Twig/FilterInterface.php +++ b/lib/Twig/FilterInterface.php @@ -30,7 +30,7 @@ interface Twig_FilterInterface function getSafe(Twig_Node $filterArgs); - function getPreserveSafety(); + function getPreservesSafety(); function getPreEscape(); diff --git a/lib/Twig/NodeVisitor/SafeAnalysis.php b/lib/Twig/NodeVisitor/SafeAnalysis.php index c3fc9d3..9f511b5 100644 --- a/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -63,7 +63,7 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface if (false !== $filter = $env->getFilter($name)) { $safe = $filter->getSafe($args); if (null === $safe) { - $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreserveSafety()); + $safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety()); } $this->setSafe($node, $safe); } else { diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/with_preserve_safety_filters.test b/test/Twig/Tests/Fixtures/tags/autoescape/with_preserve_safety_filters.test deleted file mode 100644 index cedd1bc..0000000 --- a/test/Twig/Tests/Fixtures/tags/autoescape/with_preserve_safety_filters.test +++ /dev/null @@ -1,50 +0,0 @@ ---TEST-- -"autoescape" tag handles filters preserving the safety ---TEMPLATE-- -{% autoescape true %} - -(preserve_safety is preserving safety for "html") - -1. Unsafe values are still unsafe -( var|preserve_safety|escape ) -{{ var|preserve_safety }} - -2. Safe values are still safe -( var|escape|preserve_safety ) -{{ var|escape|preserve_safety }} - -3. Re-escape values that are escaped for an other contexts -( var|escape_something|preserve_safety|escape ) -{{ var|escape_something|preserve_safety }} - -4. Still escape when using filters not declared safe -( var|escape|preserve_safety|replace({'FABIEN': 'FABPOT'})|escape ) -{{ var|escape|preserve_safety|replace({'FABIEN': 'FABPOT'}) }} - -{% endautoescape %} ---DATA-- -return array('var' => "\nTwig") ---EXPECT-- - -(preserve_safety is preserving safety for "html") - -1. Unsafe values are still unsafe -( var|preserve_safety|escape ) -<FABIEN> -TWIG - -2. Safe values are still safe -( var|escape|preserve_safety ) -<FABIEN> -TWIG - -3. Re-escape values that are escaped for an other contexts -( var|escape_something|preserve_safety|escape ) -<FABIEN> -TWIG - -4. Still escape when using filters not declared safe -( var|escape|preserve_safety|replace({'FABIEN': 'FABPOT'})|escape ) -&LT;FABPOT&GT; -TWIG - diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test b/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test new file mode 100644 index 0000000..5dfbc79 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/autoescape/with_preserves_safety_filters.test @@ -0,0 +1,50 @@ +--TEST-- +"autoescape" tag handles filters preserving the safety +--TEMPLATE-- +{% autoescape true %} + +(preserves_safety is preserving safety for "html") + +1. Unsafe values are still unsafe +( var|preserves_safety|escape ) +{{ var|preserves_safety }} + +2. Safe values are still safe +( var|escape|preserves_safety ) +{{ var|escape|preserves_safety }} + +3. Re-escape values that are escaped for an other contexts +( var|escape_something|preserves_safety|escape ) +{{ var|escape_something|preserves_safety }} + +4. Still escape when using filters not declared safe +( var|escape|preserves_safety|replace({'FABIEN': 'FABPOT'})|escape ) +{{ var|escape|preserves_safety|replace({'FABIEN': 'FABPOT'}) }} + +{% endautoescape %} +--DATA-- +return array('var' => "\nTwig") +--EXPECT-- + +(preserves_safety is preserving safety for "html") + +1. Unsafe values are still unsafe +( var|preserves_safety|escape ) +<FABIEN> +TWIG + +2. Safe values are still safe +( var|escape|preserves_safety ) +<FABIEN> +TWIG + +3. Re-escape values that are escaped for an other contexts +( var|escape_something|preserves_safety|escape ) +<FABIEN> +TWIG + +4. Still escape when using filters not declared safe +( var|escape|preserves_safety|replace({'FABIEN': 'FABPOT'})|escape ) +&LT;FABPOT&GT; +TWIG + diff --git a/test/Twig/Tests/integrationTest.php b/test/Twig/Tests/integrationTest.php index b716b86..18aba2a 100644 --- a/test/Twig/Tests/integrationTest.php +++ b/test/Twig/Tests/integrationTest.php @@ -238,7 +238,7 @@ class TestExtension extends Twig_Extension 'escape_and_nl2br' => new Twig_Filter_Method($this, 'escape_and_nl2br', array('needs_environment' => true, 'is_safe' => array('html'))), 'nl2br' => new Twig_Filter_Method($this, 'nl2br', array('pre_escape' => 'html', 'is_safe' => array('html'))), 'escape_something' => new Twig_Filter_Method($this, 'escape_something', array('is_safe' => array('something'))), - 'preserve_safety' => new Twig_Filter_Method($this, 'preserve_safety', array('preserve_safety' => array('html'))), + 'preserves_safety' => new Twig_Filter_Method($this, 'preserves_safety', array('preserves_safety' => array('html'))), '*_path' => new Twig_Filter_Method($this, 'dynamic_path'), '*_foo_*_bar' => new Twig_Filter_Method($this, 'dynamic_foo'), ); @@ -298,7 +298,7 @@ class TestExtension extends Twig_Extension return strtoupper($value); } - public function preserve_safety($value) + public function preserves_safety($value) { return strtoupper($value); } -- 1.7.2.5