bug #4475 Fix having macro variables starting with an underscore (fabpot)

This PR was merged into the 3.x branch.

Discussion
----------

Fix having macro variables starting with an underscore

Closes #4452

Commits
-------

bdb0f3c042 Fix having macro variables starting with an underscore
This commit is contained in:
Fabien Potencier
2024-11-26 21:41:33 +01:00
4 changed files with 14 additions and 5 deletions
+6 -2
View File
@@ -48,7 +48,7 @@ class MacroNode extends Node
}
foreach ($arguments->getKeyValuePairs() as $pair) {
if ('_'.self::VARARGS_NAME.'_' === $pair['key']->getAttribute('name')) {
if ("\u{035C}".self::VARARGS_NAME === $pair['key']->getAttribute('name')) {
throw new SyntaxError(\sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $pair['value']->getTemplateLine(), $pair['value']->getSourceContext());
}
}
@@ -88,9 +88,13 @@ class MacroNode extends Node
foreach ($arguments->getKeyValuePairs() as $pair) {
$name = $pair['key'];
$var = $name->getAttribute('name');
if (str_starts_with($var, "\u{035C}")) {
$var = substr($var, \strlen("\u{035C}"));
}
$compiler
->write('')
->string(trim($name->getAttribute('name'), '_'))
->string($var)
->raw(' => ')
->subcompile($name)
->raw(",\n")