From 7f58a4572eaca75aecff2da889e67ea151616011 Mon Sep 17 00:00:00 2001 From: Marc Alexander <admin@m-a-styles.de> Date: Mon, 28 Oct 2013 22:27:25 +0100 Subject: [ticket/11981] Fix code sniffer complaints PHPBB3-11981 --- phpBB/phpbb/template/context.php | 4 ++-- phpBB/phpbb/template/twig/node/includephp.php | 2 +- phpBB/phpbb/template/twig/tokenparser/includephp.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index 24234c1e4a..decd1c7956 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -285,7 +285,7 @@ class context // Search array to get correct position list($search_key, $search_value) = @each($key); - $key = NULL; + $key = null; foreach ($block as $i => $val_ary) { if ($val_ary[$search_key] === $search_value) @@ -296,7 +296,7 @@ class context } // key/value pair not found - if ($key === NULL) + if ($key === null) { return false; } diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php index 4024cf0cc8..70dcf85d62 100644 --- a/phpBB/phpbb/template/twig/node/includephp.php +++ b/phpBB/phpbb/template/twig/node/includephp.php @@ -23,7 +23,7 @@ class includephp extends \Twig_Node /** @var Twig_Environment */ protected $environment; - public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $ignoreMissing = false, $lineno, $tag = null) + public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $ignoreMissing = false, $tag = null) { $this->environment = $environment; diff --git a/phpBB/phpbb/template/twig/tokenparser/includephp.php b/phpBB/phpbb/template/twig/tokenparser/includephp.php index d906837590..25170e7214 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includephp.php +++ b/phpBB/phpbb/template/twig/tokenparser/includephp.php @@ -43,7 +43,7 @@ class includephp extends \Twig_TokenParser $stream->expect(\Twig_Token::BLOCK_END_TYPE); - return new \phpbb\template\twig\node\includephp($expr, $this->parser->getEnvironment(), $ignoreMissing, $token->getLine(), $this->getTag()); + return new \phpbb\template\twig\node\includephp($expr, $this->parser->getEnvironment(), $token->getLine(), $ignoreMissing, $this->getTag()); } /** -- cgit v1.2.1 From 02e9f6e2840d7227f158b4baf96fd9c0f6207531 Mon Sep 17 00:00:00 2001 From: Andreas Fischer <bantu@phpbb.com> Date: Tue, 29 Oct 2013 21:31:07 +0100 Subject: [task/code-sniffer] Fix argument list spacing. PHPBB3-11980 --- phpBB/phpbb/template/twig/node/includephp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php index 70dcf85d62..1d3e51f54a 100644 --- a/phpBB/phpbb/template/twig/node/includephp.php +++ b/phpBB/phpbb/template/twig/node/includephp.php @@ -23,7 +23,7 @@ class includephp extends \Twig_Node /** @var Twig_Environment */ protected $environment; - public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $ignoreMissing = false, $tag = null) + public function __construct(\Twig_Node_Expression $expr, \phpbb\template\twig\environment $environment, $lineno, $ignoreMissing = false, $tag = null) { $this->environment = $environment; -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer <bantu@phpbb.com> Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/template/asset.php | 8 -------- phpBB/phpbb/template/base.php | 8 -------- phpBB/phpbb/template/context.php | 8 -------- phpBB/phpbb/template/template.php | 8 -------- phpBB/phpbb/template/twig/definition.php | 8 -------- phpBB/phpbb/template/twig/environment.php | 8 -------- phpBB/phpbb/template/twig/extension.php | 8 -------- phpBB/phpbb/template/twig/lexer.php | 8 -------- phpBB/phpbb/template/twig/loader.php | 8 -------- phpBB/phpbb/template/twig/node/definenode.php | 8 -------- phpBB/phpbb/template/twig/node/event.php | 8 -------- phpBB/phpbb/template/twig/node/expression/binary/equalequal.php | 8 -------- .../phpbb/template/twig/node/expression/binary/notequalequal.php | 8 -------- phpBB/phpbb/template/twig/node/includenode.php | 8 -------- phpBB/phpbb/template/twig/node/includephp.php | 8 -------- phpBB/phpbb/template/twig/node/php.php | 8 -------- phpBB/phpbb/template/twig/tokenparser/defineparser.php | 8 -------- phpBB/phpbb/template/twig/tokenparser/event.php | 8 -------- phpBB/phpbb/template/twig/tokenparser/includejs.php | 8 -------- phpBB/phpbb/template/twig/tokenparser/includeparser.php | 8 -------- phpBB/phpbb/template/twig/tokenparser/includephp.php | 8 -------- phpBB/phpbb/template/twig/tokenparser/php.php | 8 -------- phpBB/phpbb/template/twig/twig.php | 8 -------- 23 files changed, 184 deletions(-) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php index 27564bf347..24e0d6698d 100644 --- a/phpBB/phpbb/template/asset.php +++ b/phpBB/phpbb/template/asset.php @@ -9,14 +9,6 @@ namespace phpbb\template; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class asset { protected $components = array(); diff --git a/phpBB/phpbb/template/base.php b/phpBB/phpbb/template/base.php index 86868707f0..6044effa1f 100644 --- a/phpBB/phpbb/template/base.php +++ b/phpBB/phpbb/template/base.php @@ -9,14 +9,6 @@ namespace phpbb\template; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - abstract class base implements template { /** diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index decd1c7956..65c7d094a0 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -9,14 +9,6 @@ namespace phpbb\template; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * Stores variables assigned to template. * diff --git a/phpBB/phpbb/template/template.php b/phpBB/phpbb/template/template.php index cf38bba522..d95b0a822c 100644 --- a/phpBB/phpbb/template/template.php +++ b/phpBB/phpbb/template/template.php @@ -9,14 +9,6 @@ namespace phpbb\template; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - interface template { diff --git a/phpBB/phpbb/template/twig/definition.php b/phpBB/phpbb/template/twig/definition.php index 2490a43f81..945c46675e 100644 --- a/phpBB/phpbb/template/twig/definition.php +++ b/phpBB/phpbb/template/twig/definition.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * This class holds all DEFINE variables from the current page load */ diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index a6c0e476f0..24bd55b3c5 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class environment extends \Twig_Environment { /** @var array */ diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 1ddb97369e..c9d2ab5799 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class extension extends \Twig_Extension { /** @var \phpbb\template\context */ diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index d832fbf84e..be53b3eb5b 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class lexer extends \Twig_Lexer { public function tokenize($code, $filename = null) diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index 910061dc0f..e01e9de467 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * Twig Template loader * @package phpBB3 diff --git a/phpBB/phpbb/template/twig/node/definenode.php b/phpBB/phpbb/template/twig/node/definenode.php index ec084d0f7d..6a9969f8c6 100644 --- a/phpBB/phpbb/template/twig/node/definenode.php +++ b/phpBB/phpbb/template/twig/node/definenode.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class definenode extends \Twig_Node { diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index 202db775ee..a8d4d06333 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class event extends \Twig_Node { diff --git a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php index 48d8b814b8..f3bbfa6691 100644 --- a/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php +++ b/phpBB/phpbb/template/twig/node/expression/binary/equalequal.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node\expression\binary; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class equalequal extends \Twig_Node_Expression_Binary { diff --git a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php index 87585dfb4c..c9c2687e08 100644 --- a/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php +++ b/phpBB/phpbb/template/twig/node/expression/binary/notequalequal.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node\expression\binary; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class notequalequal extends \Twig_Node_Expression_Binary { diff --git a/phpBB/phpbb/template/twig/node/includenode.php b/phpBB/phpbb/template/twig/node/includenode.php index 77fe7f3acb..d9b45d6407 100644 --- a/phpBB/phpbb/template/twig/node/includenode.php +++ b/phpBB/phpbb/template/twig/node/includenode.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class includenode extends \Twig_Node_Include { diff --git a/phpBB/phpbb/template/twig/node/includephp.php b/phpBB/phpbb/template/twig/node/includephp.php index 1d3e51f54a..3f4621c0a9 100644 --- a/phpBB/phpbb/template/twig/node/includephp.php +++ b/phpBB/phpbb/template/twig/node/includephp.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class includephp extends \Twig_Node { diff --git a/phpBB/phpbb/template/twig/node/php.php b/phpBB/phpbb/template/twig/node/php.php index b37759303d..2b18551266 100644 --- a/phpBB/phpbb/template/twig/node/php.php +++ b/phpBB/phpbb/template/twig/node/php.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\node; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class php extends \Twig_Node { diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index 688afec191..21add0c17c 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\tokenparser; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class defineparser extends \Twig_TokenParser { diff --git a/phpBB/phpbb/template/twig/tokenparser/event.php b/phpBB/phpbb/template/twig/tokenparser/event.php index 7cf4000909..8864e879f8 100644 --- a/phpBB/phpbb/template/twig/tokenparser/event.php +++ b/phpBB/phpbb/template/twig/tokenparser/event.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\tokenparser; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class event extends \Twig_TokenParser { diff --git a/phpBB/phpbb/template/twig/tokenparser/includejs.php b/phpBB/phpbb/template/twig/tokenparser/includejs.php index 30a99f3279..0e46915b86 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includejs.php +++ b/phpBB/phpbb/template/twig/tokenparser/includejs.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\tokenparser; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class includejs extends \Twig_TokenParser { diff --git a/phpBB/phpbb/template/twig/tokenparser/includeparser.php b/phpBB/phpbb/template/twig/tokenparser/includeparser.php index 715c0ec84d..d351f1b4cd 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includeparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/includeparser.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\tokenparser; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class includeparser extends \Twig_TokenParser_Include { diff --git a/phpBB/phpbb/template/twig/tokenparser/includephp.php b/phpBB/phpbb/template/twig/tokenparser/includephp.php index 25170e7214..1b3d1742e3 100644 --- a/phpBB/phpbb/template/twig/tokenparser/includephp.php +++ b/phpBB/phpbb/template/twig/tokenparser/includephp.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\tokenparser; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class includephp extends \Twig_TokenParser { diff --git a/phpBB/phpbb/template/twig/tokenparser/php.php b/phpBB/phpbb/template/twig/tokenparser/php.php index e4f70fb9b1..13688af2f6 100644 --- a/phpBB/phpbb/template/twig/tokenparser/php.php +++ b/phpBB/phpbb/template/twig/tokenparser/php.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig\tokenparser; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - class php extends \Twig_TokenParser { diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 9df9310427..ddadcfd89a 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -9,14 +9,6 @@ namespace phpbb\template\twig; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * Twig Template class. * @package phpBB3 -- cgit v1.2.1 From ef1f99183796f8e246f96bca54ca439bf8ea1750 Mon Sep 17 00:00:00 2001 From: Andreas Fischer <bantu@phpbb.com> Date: Wed, 30 Oct 2013 13:37:29 +0100 Subject: [task/code-sniffer] Replace spaces with tabs. PHPBB3-11980 --- phpBB/phpbb/template/twig/extension.php | 74 +++++++++++++-------------- phpBB/phpbb/template/twig/node/event.php | 10 ++-- phpBB/phpbb/template/twig/tokenparser/php.php | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index c9d2ab5799..6847dbd9f8 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -40,11 +40,11 @@ class extension extends \Twig_Extension return 'phpbb'; } - /** - * Returns the token parser instance to add to the existing list. - * - * @return array An array of Twig_TokenParser instances - */ + /** + * Returns the token parser instance to add to the existing list. + * + * @return array An array of Twig_TokenParser instances + */ public function getTokenParsers() { return array( @@ -58,36 +58,36 @@ class extension extends \Twig_Extension ); } - /** - * Returns a list of filters to add to the existing list. - * - * @return array An array of filters - */ - public function getFilters() - { + /** + * Returns a list of filters to add to the existing list. + * + * @return array An array of filters + */ + public function getFilters() + { return array( new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), new \Twig_SimpleFilter('addslashes', 'addslashes'), ); - } - - /** - * Returns a list of global functions to add to the existing list. - * - * @return array An array of global functions - */ - public function getFunctions() - { + } + + /** + * Returns a list of global functions to add to the existing list. + * + * @return array An array of global functions + */ + public function getFunctions() + { return array( new \Twig_SimpleFunction('lang', array($this, 'lang')), ); } - /** - * Returns a list of operators to add to the existing list. - * - * @return array An array of operators - */ + /** + * Returns a list of operators to add to the existing list. + * + * @return array An array of operators + */ public function getOperators() { return array( @@ -118,19 +118,19 @@ class extension extends \Twig_Extension 'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), ), ); - } + } /** - * Grabs a subset of a loop - * - * @param Twig_Environment $env A Twig_Environment instance - * @param mixed $item A variable - * @param integer $start Start of the subset - * @param integer $end End of the subset - * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array) - * - * @return mixed The sliced variable - */ + * Grabs a subset of a loop + * + * @param Twig_Environment $env A Twig_Environment instance + * @param mixed $item A variable + * @param integer $start Start of the subset + * @param integer $end End of the subset + * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array) + * + * @return mixed The sliced variable + */ function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false) { // We do almost the same thing as Twig's slice (array_slice), except when $end is positive diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index a8d4d06333..7a1181a866 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -49,10 +49,10 @@ class event extends \Twig_Node // templates on page load rather than at compile. This is // slower, but makes developing extensions easier (no need to // purge the cache when a new event template file is added) - $compiler - ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n") - ->indent() - ; + $compiler + ->write("if (\$this->env->getLoader()->exists('@{$ext_namespace}/{$location}.html')) {\n") + ->indent() + ; } if (defined('DEBUG') || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) @@ -71,7 +71,7 @@ class event extends \Twig_Node { $compiler ->outdent() - ->write("}\n\n") + ->write("}\n\n") ; } } diff --git a/phpBB/phpbb/template/twig/tokenparser/php.php b/phpBB/phpbb/template/twig/tokenparser/php.php index 13688af2f6..b427969e2d 100644 --- a/phpBB/phpbb/template/twig/tokenparser/php.php +++ b/phpBB/phpbb/template/twig/tokenparser/php.php @@ -45,5 +45,5 @@ class php extends \Twig_TokenParser public function getTag() { return 'PHP'; - } + } } -- cgit v1.2.1 From b49d3a1851330d64009c8050132e50b093172559 Mon Sep 17 00:00:00 2001 From: Nathan Guse <nathaniel.guse@gmail.com> Date: Mon, 4 Nov 2013 12:21:12 -0600 Subject: [ticket/11943] Do not quote the value when it is exactly true, false, or null Quoting these can change the meaning of the value (e.g. 'false' == true) PHPBB3-11943 --- phpBB/phpbb/template/twig/lexer.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index be53b3eb5b..8c52fa65b2 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -129,6 +129,14 @@ class lexer extends \Twig_Lexer // Replace template variables with start/end to parse variables (' ~ TEST ~ '.html) $matches[2] = preg_replace('#{([a-zA-Z0-9_\.$]+)}#', "'~ \$1 ~'", $matches[2]); + // If the second item is exactly one of a few key words, + // do not quote it as it changes the meaning + // http://tracker.phpbb.com/browse/PHPBB3-11943 + if (in_array($matches[2], array('false', 'true', 'null'))) + { + return "<!-- {$matches[1]} {$matches[2]} -->"; + } + // Surround the matches in single quotes ('' ~ TEST ~ '.html') return "<!-- {$matches[1]} '{$matches[2]}' -->"; }; -- cgit v1.2.1 From da332aa0a5cbeabbcce5551ee955c701fc2a1d73 Mon Sep 17 00:00:00 2001 From: Nathan Guse <nathaniel.guse@gmail.com> Date: Fri, 8 Nov 2013 19:55:16 -0600 Subject: [ticket/11943] Require stricter DEFINE statements for templates PHPBB3-11943 --- phpBB/phpbb/template/twig/lexer.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 8c52fa65b2..efd6a0bd84 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -69,7 +69,7 @@ class lexer extends \Twig_Lexer // Fix tokens that may have inline variables (e.g. <!-- DEFINE $TEST = '{FOO}') $code = $this->fix_inline_variable_tokens(array( - 'DEFINE \$[a-zA-Z0-9_]+ =', + //'DEFINE \$[a-zA-Z0-9_]+ =', // Disabling for ticket 11943 'INCLUDE', 'INCLUDEPHP', 'INCLUDEJS', @@ -129,14 +129,6 @@ class lexer extends \Twig_Lexer // Replace template variables with start/end to parse variables (' ~ TEST ~ '.html) $matches[2] = preg_replace('#{([a-zA-Z0-9_\.$]+)}#', "'~ \$1 ~'", $matches[2]); - // If the second item is exactly one of a few key words, - // do not quote it as it changes the meaning - // http://tracker.phpbb.com/browse/PHPBB3-11943 - if (in_array($matches[2], array('false', 'true', 'null'))) - { - return "<!-- {$matches[1]} {$matches[2]} -->"; - } - // Surround the matches in single quotes ('' ~ TEST ~ '.html') return "<!-- {$matches[1]} '{$matches[2]}' -->"; }; -- cgit v1.2.1 From 6370970f13d58f617379da64efb1f88a522f3f03 Mon Sep 17 00:00:00 2001 From: Nathan Guse <nathaniel.guse@gmail.com> Date: Fri, 8 Nov 2013 22:30:58 -0600 Subject: [ticket/11943] Split fix_inline_variable_tokens into 3 steps DEFINE shouldn't add/remove surrounding quotes, but must have the inline variable tokens fixed PHPBB3-11943 --- phpBB/phpbb/template/twig/lexer.php | 60 ++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index efd6a0bd84..f4efc58540 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -68,8 +68,20 @@ class lexer extends \Twig_Lexer ); // Fix tokens that may have inline variables (e.g. <!-- DEFINE $TEST = '{FOO}') + $code = $this->strip_surrounding_quotes(array( + 'INCLUDE', + 'INCLUDEPHP', + 'INCLUDEJS', + 'INCLUDECSS', + ), $code); $code = $this->fix_inline_variable_tokens(array( - //'DEFINE \$[a-zA-Z0-9_]+ =', // Disabling for ticket 11943 + 'DEFINE \$[a-zA-Z0-9_]+ =', + 'INCLUDE', + 'INCLUDEPHP', + 'INCLUDEJS', + 'INCLUDECSS', + ), $code); + $code = $this->add_surrounding_quotes(array( 'INCLUDE', 'INCLUDEPHP', 'INCLUDEJS', @@ -107,10 +119,30 @@ class lexer extends \Twig_Lexer return parent::tokenize($code, $filename); } + /** + * Strip surrounding quotes + * + * First step to fix tokens that may have inline variables + * E.g. <!-- INCLUDE '{TEST}.html' to <!-- INCLUDE {TEST}.html + * + * @param array $tokens array of tokens to search for (imploded to a regular expression) + * @param string $code + * @return string + */ + protected function strip_surrounding_quotes($tokens, $code) + { + // Remove matching quotes at the beginning/end if a statement; + // E.g. 'asdf'"' -> asdf'" + // E.g. "asdf'"" -> asdf'" + // E.g. 'asdf'" -> 'asdf'" + return preg_replace('#<!-- (' . implode('|', $tokens) . ') (([\'"])?(.*?)\1) -->#', '<!-- $1 $2 -->', $code); + } + /** * Fix tokens that may have inline variables * - * E.g. <!-- INCLUDE {TEST}.html + * Second step to fix tokens that may have inline variables + * E.g. <!-- INCLUDE '{TEST}.html' to <!-- INCLUDE ' ~ {TEST} ~ '.html * * @param array $tokens array of tokens to search for (imploded to a regular expression) * @param string $code @@ -120,22 +152,30 @@ class lexer extends \Twig_Lexer { $callback = function($matches) { - // Remove matching quotes at the beginning/end if a statement; - // E.g. 'asdf'"' -> asdf'" - // E.g. "asdf'"" -> asdf'" - // E.g. 'asdf'" -> 'asdf'" - $matches[2] = preg_replace('#^([\'"])?(.*?)\1$#', '$2', $matches[2]); - // Replace template variables with start/end to parse variables (' ~ TEST ~ '.html) $matches[2] = preg_replace('#{([a-zA-Z0-9_\.$]+)}#', "'~ \$1 ~'", $matches[2]); - // Surround the matches in single quotes ('' ~ TEST ~ '.html') - return "<!-- {$matches[1]} '{$matches[2]}' -->"; + return "<!-- {$matches[1]} {$matches[2]} -->"; }; return preg_replace_callback('#<!-- (' . implode('|', $tokens) . ') (.+?) -->#', $callback, $code); } + /** + * Add surrounding quotes + * + * Last step to fix tokens that may have inline variables + * E.g. <!-- INCLUDE '{TEST}.html' to <!-- INCLUDE '' ~ {TEST} ~ '.html' + * + * @param array $tokens array of tokens to search for (imploded to a regular expression) + * @param string $code + * @return string + */ + protected function add_surrounding_quotes($tokens, $code) + { + return preg_replace('#<!-- (' . implode('|', $tokens) . ') (.+?) -->#', '<!-- $1 \'$2\' -->', $code); + } + /** * Fix begin tokens (convert our BEGIN to Twig for) * -- cgit v1.2.1 From 2e5117a71eb64c734e5738235c44ef92818ca33b Mon Sep 17 00:00:00 2001 From: Nathan Guse <nathaniel.guse@gmail.com> Date: Sat, 9 Nov 2013 11:14:55 -0600 Subject: [ticket/11943] Throw an exception if DEFINE is setup improperly PHPBB3-11943 --- phpBB/phpbb/template/twig/tokenparser/defineparser.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/phpbb/template') diff --git a/phpBB/phpbb/template/twig/tokenparser/defineparser.php b/phpBB/phpbb/template/twig/tokenparser/defineparser.php index 21add0c17c..8484f2e81a 100644 --- a/phpBB/phpbb/template/twig/tokenparser/defineparser.php +++ b/phpBB/phpbb/template/twig/tokenparser/defineparser.php @@ -30,6 +30,13 @@ class defineparser extends \Twig_TokenParser $stream->next(); $value = $this->parser->getExpressionParser()->parseExpression(); + if ($value instanceof \Twig_Node_Expression_Name) + { + // This would happen if someone improperly formed their DEFINE syntax + // e.g. <!-- DEFINE $VAR = foo --> + throw new \Twig_Error_Syntax('Invalid DEFINE', $token->getLine(), $this->parser->getFilename()); + } + $stream->expect(\Twig_Token::BLOCK_END_TYPE); } else { $capture = true; -- cgit v1.2.1