mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
[ExpressionParser] forbids true, false, null and none keywords for variables names.
This commit is contained in:
@@ -539,10 +539,11 @@ class Twig_ExpressionParser
|
|||||||
$targets = array();
|
$targets = array();
|
||||||
while (true) {
|
while (true) {
|
||||||
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
||||||
if (in_array($token->getValue(), array('true', 'false', 'none'))) {
|
$value = $token->getValue();
|
||||||
throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $token->getValue()), $token->getLine(), $this->parser->getFilename());
|
if (in_array(strtolower($value), array('true', 'false', 'none', 'null'))) {
|
||||||
|
throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s"', $value), $token->getLine(), $this->parser->getFilename());
|
||||||
}
|
}
|
||||||
$targets[] = new Twig_Node_Expression_AssignName($token->getValue(), $token->getLine());
|
$targets[] = new Twig_Node_Expression_AssignName($value, $token->getLine());
|
||||||
|
|
||||||
if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
|
if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -27,8 +27,13 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('{% set false = "foo" %}'),
|
array('{% set false = "foo" %}'),
|
||||||
|
array('{% set FALSE = "foo" %}'),
|
||||||
array('{% set true = "foo" %}'),
|
array('{% set true = "foo" %}'),
|
||||||
|
array('{% set TRUE = "foo" %}'),
|
||||||
array('{% set none = "foo" %}'),
|
array('{% set none = "foo" %}'),
|
||||||
|
array('{% set NONE = "foo" %}'),
|
||||||
|
array('{% set null = "foo" %}'),
|
||||||
|
array('{% set NULL = "foo" %}'),
|
||||||
array('{% set 3 = "foo" %}'),
|
array('{% set 3 = "foo" %}'),
|
||||||
array('{% set 1 + 2 = "foo" %}'),
|
array('{% set 1 + 2 = "foo" %}'),
|
||||||
array('{% set "bar" = "foo" %}'),
|
array('{% set "bar" = "foo" %}'),
|
||||||
|
|||||||
Reference in New Issue
Block a user