From b49d3a1851330d64009c8050132e50b093172559 Mon Sep 17 00:00:00 2001 From: Nathan Guse 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 ""; + } + // Surround the matches in single quotes ('' ~ TEST ~ '.html') return ""; }; -- cgit v1.2.1 From da332aa0a5cbeabbcce5551ee955c701fc2a1d73 Mon Sep 17 00:00:00 2001 From: Nathan Guse 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. "; - } - // Surround the matches in single quotes ('' ~ TEST ~ '.html') return ""; }; -- cgit v1.2.1 From 6370970f13d58f617379da64efb1f88a522f3f03 Mon Sep 17 00:00:00 2001 From: Nathan Guse 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. #', '', $code); + } + /** * Fix tokens that may have inline variables * - * E.g. "; + return ""; }; return preg_replace_callback('##', $callback, $code); } + /** + * Add surrounding quotes + * + * Last step to fix tokens that may have inline variables + * E.g. #', '', $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 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. + 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