mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 15:48:42 +00:00
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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user