Skip to content

Commit d450575

Browse files
committed
bug #4395 Do not allow : as macro definition separator (fabpot)
This PR was merged into the 3.x branch. Discussion ---------- Do not allow : as macro definition separator Commits ------- 831e69b Do not allow : as macro definition separator
2 parents 3eda65e + 831e69b commit d450575

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ExpressionParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ public function parseArguments($namedArguments = false, $definition = false)
735735
}
736736

737737
$name = null;
738-
if ($namedArguments && (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || ($token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':')))) {
738+
if ($namedArguments && (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || (!$definition && $token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':')))) {
739739
if (!$value instanceof NameExpression) {
740740
throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
741741
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
"macro" tag does not support : as a separator in definition, only = is supported
3+
--TEMPLATE--
4+
{% macro test(foo: "foo") -%}
5+
{{ foo }}
6+
{%- endmacro %}
7+
--DATA--
8+
return []
9+
--EXCEPTION--
10+
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.

0 commit comments

Comments
 (0)