diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index be53b3eb5b..f4efc58540 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -68,6 +68,12 @@ 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) * 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; diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 39eb08ab79..6e9b7d3ee9 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -158,7 +158,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n((\$VALUE == 'abc'))\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?[]|foobar|", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n((\$VALUE == 'abc'))\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?[]|foobar|false", ), array( 'define_advanced.html', @@ -561,4 +561,12 @@ EOT $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); } + + /** + * @expectedException Twig_Error_Syntax + */ + public function test_define_error() + { + $this->run_template('define_error.html', array(), array(), array(), ''); + } } diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index e7ce7f7def..276d2ebb99 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -29,3 +29,9 @@ $VALUE == 'abc' [{$VALUE}] foobar|{$TEST}| + + +true + +false + diff --git a/tests/template/templates/define_error.html b/tests/template/templates/define_error.html new file mode 100644 index 0000000000..72ab1ba033 --- /dev/null +++ b/tests/template/templates/define_error.html @@ -0,0 +1,2 @@ + +{$VAR}