Skip to content

[BUG]: Volt autoescape escapes the output of content(), get_content() and partial() #17794

Todo

Description

@niden

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>&lt;p&gt;Hello&lt;/p&gt;</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(): the autoescape wrap. Only super() is exempt.
  • phalcon/Mvc/View/Engine/Volt/Compiler.zep, functionCall(): content() and get_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.

Activity

  1. self-assigned this
    on Nov 25, 2026
  2. added theissue type on Nov 25, 2026
  3. added
    bug
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

7.0bugstatus: medium

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions