HubSpot / jinjava

Jinja template engine for Java
Apache License 2.0
700 stars 169 forks source link

Only unwrap raw tags from set block when fully resolved #1167

Closed jasmith-hs closed 7 months ago

jasmith-hs commented 7 months ago

When rendering a set block with eager execution, if it cannot be fully resolved, it must be deferred and reconstructed If there are raw tags inside of it when this happens, the reconstructed image will not be correct.

This input:

{% set foo %}
{% if deferred %}
{% raw %}{{ 'fire' }}{% endraw %}
{% endif %}
{% endset %}
{% print foo %}

Would incorrectly become:

{% set foo %}
{% if deferred %}
{{ 'fire' }}
{% endif %}
{% endset %}
{% print foo %}

To fix this, I've made it so that we solve the problem from https://github.com/HubSpot/jinjava/pull/1080 in a different manner, by only unwrapping the raw tags if the result has been fully resolved. The simplest way to unwrap the raw tags is by doing a renderFlat.