Repository navigation
Description
Describe the bug
This is the second part of #17678. The first part (escaping filters such as |e are escaped two times) stays in #17678 for 5.x. This part changes the rendered output, so it is for v7.
When autoescape is on, Compiler::compileEcho() wraps every {{ … }} in $this->escaper->html(). The only exception is super(). The functions content(), get_content() and partial() return HTML that Volt already rendered. Volt escapes this HTML again, and the page shows the markup as text.
To Reproduce
use Phalcon\Mvc\View\Engine\Volt\Compiler;
$compiler = new Compiler();
$compiler->setOption('autoescape', true);
echo $compiler->compileString('{{ content() }}'), PHP_EOL;
echo $compiler->compileString('{{ get_content() }}'), PHP_EOL;
echo $compiler->compileString('{{ partial("shared/menu") }}'), PHP_EOL;Output:
<?= $this->escaper->html($this->getContent()) ?>
<?= $this->escaper->html($this->getContent()) ?>
<?= $this->escaper->html($this->partial('shared/menu')) ?>With a layout <main>{{ content() }}</main> and an action view <p>Hello</p>, the page shows:
<main><p>Hello</p></main>Expected behavior
<?= $this->getContent() ?>
<?= $this->getContent() ?>
<?= $this->partial('shared/menu') ?><main><p>Hello</p></main>Details
- Phalcon version: 5.x (
master) - Target: 7.0
Additional context
Location:
phalcon/Mvc/View/Engine/Volt/Compiler.zep,compileEcho(): theautoescapewrap. Onlysuper()is exempt.phalcon/Mvc/View/Engine/Volt/Compiler.zep,functionCall():content()andget_content()compile to$this->getContent().partial()compiles to$this->partial(...).
Why v7: the fix changes the rendered output of content(), get_content() and partial() from escaped text to HTML. Applications that use these functions with autoescape on today use {% autoescape false %} or turn autoescape off. Their output stays the same. Other applications show escaped markup today, and they will show HTML after the fix.
Proposed fix: in compileEcho(), do not add the outer html() when the outermost node is a call to the built-in content(), get_content() or partial(). Use the same approach as super(). A user function or an extension that redefines one of these names must keep the html() wrap.
Related: a raw filter (the NFR that #17678 mentions) gives users a way to mark other output as safe. It fits in the same release.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity