Do not allow : as macro definition separator

This commit is contained in:
Fabien Potencier
2024-10-14 10:41:48 +02:00
parent 3eda65e94f
commit 831e69b77e
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -735,7 +735,7 @@ class ExpressionParser
}
$name = null;
if ($namedArguments && (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || ($token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':')))) {
if ($namedArguments && (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || (!$definition && $token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':')))) {
if (!$value instanceof NameExpression) {
throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
}
@@ -0,0 +1,10 @@
--TEST--
"macro" tag does not support : as a separator in definition, only = is supported
--TEMPLATE--
{% macro test(foo: "foo") -%}
{{ foo }}
{%- endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\SyntaxError: Arguments must be separated by a comma. Unexpected token "punctuation" of value ":" ("punctuation" expected with value ",") in "index.twig" at line 2.