mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 04:27:00 +00:00
Make the raw filter "sticky"
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# 4.0.0 (2024-XX-XX)
|
||||
|
||||
* Make the `raw` filter sticky
|
||||
* Add back the `if` condition on `for` loops
|
||||
* Add return types to all ExtensionInterface methods (`getFunctions()`, `getFilters()`, etc.)
|
||||
* Add support for recursive loops (via the `loop()` function)
|
||||
|
||||
@@ -32,6 +32,10 @@ class RawFilter extends FilterExpression
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
$compiler->subcompile($this->getNode('node'));
|
||||
$compiler
|
||||
->raw('(is_scalar($tmp = ')
|
||||
->subcompile($this->getNode('node'))
|
||||
->raw(') ? new Markup($tmp, $this->env->getCharset()) : $tmp)')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,17 @@
|
||||
"raw" filter excludes a variable from being escaped
|
||||
--TEMPLATE--
|
||||
{{ br|raw }}
|
||||
{% set br1 = '<br>'|raw %}
|
||||
{{ br1 }}
|
||||
{{ include('included', {br: '<br>'|raw, br1: br1}) }}
|
||||
--TEMPLATE(included)--
|
||||
{{ br }}
|
||||
{{ br1 }}
|
||||
--DATA--
|
||||
return ['br' => '<br>']
|
||||
--EXPECT--
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
@@ -32,7 +32,7 @@ class RawTest extends NodeTestCase
|
||||
$node = new RawFilter(new ConstantExpression('foo', 12));
|
||||
|
||||
return [
|
||||
[$node, '"foo"'],
|
||||
[$node, '(is_scalar($tmp = "foo") ? new Markup($tmp, $this->env->getCharset()) : $tmp)'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ yield from (\$_v1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \
|
||||
\$parent = \$context;
|
||||
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
|
||||
foreach (\$iterator as \$context["_key"] => \$context["item"]) {
|
||||
yield from CoreExtension::getAttribute(\$this->env, \$this->source, \$context["loop"], "__invoke", arguments: [CoreExtension::getAttribute(\$this->env, \$this->source, \$context["item"], "children", arguments: [], lineno: 1)], type: "method", lineno: 1);
|
||||
yield from (is_scalar(\$tmp = CoreExtension::getAttribute(\$this->env, \$this->source, \$context["loop"], "__invoke", arguments: [CoreExtension::getAttribute(\$this->env, \$this->source, \$context["item"], "children", arguments: [], lineno: 1)], type: "method", lineno: 1)) ? new Markup(\$tmp, \$this->env->getCharset()) : \$tmp);
|
||||
}
|
||||
unset(\$context['_key'], \$context['item'], \$context['loop']);
|
||||
\$context = array_intersect_key(\$context, \$parent) + \$parent;
|
||||
|
||||
Reference in New Issue
Block a user