Skip to content

Make the raw filter more "sticky"#4577

Merged
fabpot merged 1 commit into
twigphp:4.xfrom
fabpot:raw-filter-propagate
Feb 14, 2025
Merged

Make the raw filter more "sticky"#4577
fabpot merged 1 commit into
twigphp:4.xfrom
fabpot:raw-filter-propagate

Conversation

@fabpot

@fabpot fabpot commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

When using {{ foo|raw }}, the expression won't be escaped as expected.

But if you store the result and reuse it afterwards, the value is not considered "safe" anymore:

{% set bar = foo|raw %}{{ bar }}

Here bar will be escaped.

For Twig 4.x, I propose to make the raw filter "sticky" by wrapping the value with Markup. That way, the second example won't be escaped as expected.

@fabpot fabpot merged commit 82c88d3 into twigphp:4.x Feb 14, 2025
@fabpot fabpot deleted the raw-filter-propagate branch February 14, 2025 15:04
@stof

stof commented Feb 14, 2025

Copy link
Copy Markdown
Member

Is the raw filter properly optimized away when auto-escaping gets applied on a location, to avoid wrapping the value in a Markup object to have it cast to string right after (both as final filter before display and as filter in a location expecting a pre-escaped value ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants