mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
allowed string operators as variables names in assignments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
* 1.42.1 (2019-XX-XX)
|
||||
|
||||
* n/a
|
||||
* allowed string operators as variables names in assignments
|
||||
|
||||
* 1.42.0 (2019-05-31)
|
||||
|
||||
|
||||
@@ -649,7 +649,13 @@ class ExpressionParser
|
||||
$stream = $this->parser->getStream();
|
||||
$targets = [];
|
||||
while (true) {
|
||||
$token = $stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
||||
$token = $this->parser->getCurrentToken();
|
||||
if ($stream->test(Token::OPERATOR_TYPE) && preg_match(Lexer::REGEX_NAME, $token->getValue())) {
|
||||
// in this context, string operators are variable names
|
||||
$this->parser->getStream()->next();
|
||||
} else {
|
||||
$stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
||||
}
|
||||
$value = $token->getValue();
|
||||
if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) {
|
||||
throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext());
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
Twig supports the string operators as variable names in assignments
|
||||
--TEMPLATE--
|
||||
{% for matches in [1, 2] %}
|
||||
{{- matches }}
|
||||
{% endfor %}
|
||||
|
||||
{% set matches = [1, 2] %}
|
||||
|
||||
OK
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
1
|
||||
2
|
||||
|
||||
|
||||
OK
|
||||
Reference in New Issue
Block a user