mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
fixed hardcoded name escaping
This commit is contained in:
@@ -19,6 +19,10 @@ class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
|
||||
*/
|
||||
public function compile(Twig_Compiler $compiler)
|
||||
{
|
||||
$compiler->raw(sprintf('$context[\'%s\']', $this->getAttribute('name')));
|
||||
$compiler
|
||||
->raw('$context[')
|
||||
->string($this->getAttribute('name'))
|
||||
->raw(']')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,11 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
|
||||
} elseif (isset($specialVars[$name])) {
|
||||
$compiler->raw($specialVars[$name]);
|
||||
} else {
|
||||
$compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
|
||||
$compiler
|
||||
->raw('$this->getContext($context, ')
|
||||
->string($name)
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class Twig_Tests_Node_Expression_AssignNameTest extends Twig_Tests_Node_TestCase
|
||||
$node = new Twig_Node_Expression_AssignName('foo', 0);
|
||||
|
||||
return array(
|
||||
array($node, '$context[\'foo\']'),
|
||||
array($node, '$context["foo"]'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Tests_Node_TestCase
|
||||
$attr = new Twig_Node_Expression_Constant('bar', 0);
|
||||
$args = new Twig_Node();
|
||||
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ANY_CALL, 0);
|
||||
$tests[] = array($node, '$this->getAttribute($this->getContext($context, \'foo\'), "bar", array(), "any", false)');
|
||||
$tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "any", false)');
|
||||
|
||||
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 0);
|
||||
$tests[] = array($node, '$this->getAttribute($this->getContext($context, \'foo\'), "bar", array(), "array", false)');
|
||||
$tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "array", false)');
|
||||
|
||||
|
||||
$args = new Twig_Node(array(
|
||||
@@ -60,7 +60,7 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Tests_Node_TestCase
|
||||
new Twig_Node_Expression_Constant('bar', 0),
|
||||
));
|
||||
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::METHOD_CALL, 0);
|
||||
$tests[] = array($node, '$this->getAttribute($this->getContext($context, \'foo\'), "bar", array($this->getContext($context, \'foo\'), "bar", ), "method", false)');
|
||||
$tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array($this->getContext($context, "foo"), "bar", ), "method", false)');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Tests_Node_TestCase
|
||||
$env = new Twig_Environment(null, array('strict_variables' => true));
|
||||
|
||||
return array(
|
||||
array($node, '$this->getContext($context, \'foo\')', $env),
|
||||
array($node, '$this->getContext($context, \'foo\')'),
|
||||
array($node, '$this->getContext($context, "foo")', $env),
|
||||
array($node, '$this->getContext($context, "foo")'),
|
||||
array($self, '$this'),
|
||||
array($context, '$context'),
|
||||
);
|
||||
|
||||
@@ -64,9 +64,9 @@ class Twig_Tests_Node_ForTest extends Twig_Tests_Node_TestCase
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'items'));
|
||||
foreach (\$context['_seq'] as \$context['key'] => \$context['item']) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "items"));
|
||||
foreach (\$context['_seq'] as \$context["key"] => \$context["item"]) {
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
}
|
||||
\$_parent = \$context['_parent'];
|
||||
unset(\$context['_seq'], \$context['_iterated'], \$context['key'], \$context['item'], \$context['_parent'], \$context['loop']);
|
||||
@@ -85,7 +85,7 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'values'));
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "values"));
|
||||
\$context['loop'] = array(
|
||||
'parent' => \$context['_parent'],
|
||||
'index0' => 0,
|
||||
@@ -99,8 +99,8 @@ if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_
|
||||
\$context['loop']['length'] = \$length;
|
||||
\$context['loop']['last'] = 1 === \$length;
|
||||
}
|
||||
foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
++\$context['loop']['index0'];
|
||||
++\$context['loop']['index'];
|
||||
\$context['loop']['first'] = false;
|
||||
@@ -127,19 +127,19 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'values'));
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "values"));
|
||||
\$context['loop'] = array(
|
||||
'parent' => \$context['_parent'],
|
||||
'index0' => 0,
|
||||
'index' => 1,
|
||||
'first' => true,
|
||||
);
|
||||
foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
|
||||
foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
|
||||
if (!(true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
++\$context['loop']['index0'];
|
||||
++\$context['loop']['index'];
|
||||
\$context['loop']['first'] = false;
|
||||
@@ -161,7 +161,7 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
\$context['_parent'] = (array) \$context;
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, 'values'));
|
||||
\$context['_seq'] = twig_ensure_traversable(\$this->getContext(\$context, "values"));
|
||||
\$context['_iterated'] = false;
|
||||
\$context['loop'] = array(
|
||||
'parent' => \$context['_parent'],
|
||||
@@ -176,8 +176,8 @@ if (is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_
|
||||
\$context['loop']['length'] = \$length;
|
||||
\$context['loop']['last'] = 1 === \$length;
|
||||
}
|
||||
foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) {
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
\$context['_iterated'] = true;
|
||||
++\$context['loop']['index0'];
|
||||
++\$context['loop']['index'];
|
||||
@@ -189,7 +189,7 @@ foreach (\$context['_seq'] as \$context['k'] => \$context['v']) {
|
||||
}
|
||||
}
|
||||
if (!\$context['_iterated']) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
}
|
||||
\$_parent = \$context['_parent'];
|
||||
unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']);
|
||||
|
||||
@@ -55,7 +55,7 @@ class Twig_Tests_Node_IfTest extends Twig_Tests_Node_TestCase
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
if (true) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
}
|
||||
EOF
|
||||
);
|
||||
@@ -71,9 +71,9 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
if (true) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
} elseif (false) {
|
||||
echo \$this->getContext(\$context, 'bar');
|
||||
echo \$this->getContext(\$context, "bar");
|
||||
}
|
||||
EOF
|
||||
);
|
||||
@@ -87,9 +87,9 @@ EOF
|
||||
|
||||
$tests[] = array($node, <<<EOF
|
||||
if (true) {
|
||||
echo \$this->getContext(\$context, 'foo');
|
||||
echo \$this->getContext(\$context, "foo");
|
||||
} else {
|
||||
echo \$this->getContext(\$context, 'bar');
|
||||
echo \$this->getContext(\$context, "bar");
|
||||
}
|
||||
EOF
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ class Twig_Tests_Node_ImportTest extends Twig_Tests_Node_TestCase
|
||||
$var = new Twig_Node_Expression_AssignName('macro', 0);
|
||||
$node = new Twig_Node_Import($macro, $var, 0);
|
||||
|
||||
$tests[] = array($node, '$context[\'macro\'] = $this->env->loadTemplate("foo.twig");');
|
||||
$tests[] = array($node, '$context["macro"] = $this->env->loadTemplate("foo.twig");');
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
|
||||
{
|
||||
\$context = array_merge(\$this->env->getGlobals(), \$context);
|
||||
|
||||
\$context['macro'] = \$this->env->loadTemplate("foo.twig");
|
||||
\$context["macro"] = \$this->env->loadTemplate("foo.twig");
|
||||
\$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class Twig_Tests_Node_SetTest extends Twig_Tests_Node_TestCase
|
||||
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0);
|
||||
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 0)), array(), 0);
|
||||
$node = new Twig_Node_Set(false, $names, $values, 0);
|
||||
$tests[] = array($node, '$context[\'foo\'] = "foo";');
|
||||
$tests[] = array($node, '$context["foo"] = "foo";');
|
||||
|
||||
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0);
|
||||
$values = new Twig_Node(array(new Twig_Node_Print(new Twig_Node_Expression_Constant('foo', 0), 0)), array(), 0);
|
||||
@@ -51,20 +51,20 @@ class Twig_Tests_Node_SetTest extends Twig_Tests_Node_TestCase
|
||||
$tests[] = array($node, <<<EOF
|
||||
ob_start();
|
||||
echo "foo";
|
||||
\$context['foo'] = new Twig_Markup(ob_get_clean());
|
||||
\$context["foo"] = new Twig_Markup(ob_get_clean());
|
||||
EOF
|
||||
);
|
||||
|
||||
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0);
|
||||
$values = new Twig_Node_Text('foo', 0);
|
||||
$node = new Twig_Node_Set(true, $names, $values, 0);
|
||||
$tests[] = array($node, '$context[\'foo\'] = new Twig_Markup("foo");');
|
||||
$tests[] = array($node, '$context["foo"] = new Twig_Markup("foo");');
|
||||
|
||||
$names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0), new Twig_Node_Expression_AssignName('bar', 0)), array(), 0);
|
||||
$values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 0), new Twig_Node_Expression_Name('bar', 0)), array(), 0);
|
||||
$node = new Twig_Node_Set(false, $names, $values, 0);
|
||||
$tests[] = array($node, <<<EOF
|
||||
list(\$context['foo'], \$context['bar']) = array("foo", \$this->getContext(\$context, 'bar'));
|
||||
list(\$context["foo"], \$context["bar"]) = array("foo", \$this->getContext(\$context, "bar"));
|
||||
EOF
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user