Skip to content

Fix double-encoding when using escape filter with HtmlEncoder - #866

Merged
sebastienros merged 2 commits into
mainfrom
copilot/fix-encoded-liquid-tags
Nov 17, 2025
Merged

Fix double-encoding when using escape filter with HtmlEncoder#866
sebastienros merged 2 commits into
mainfrom
copilot/fix-encoded-liquid-tags

Conversation

Copilot AI commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

The escape and escape_once filters were causing double-encoding when templates rendered with an HtmlEncoder. Content inside {% capture %}{% raw %}...{% endraw %}{% endcapture %} blocks piped through | escape resulted in < instead of <.

{% capture r %}
{% raw %}
<ul>item</ul>
{% endraw %}
{% endcapture %}
{{ r | escape }}

Previously produced: &amp;lt;ul&amp;gt;item&lt;/ul&amp;gt; (double-encoded)
Now produces: &lt;ul&gt;item&lt;/ul&gt; (correctly encoded once)

Changes

Core Fix

  • Modified MiscFilters.Escape and MiscFilters.EscapeOnce to return StringValue with encode: false
  • Prevents the HtmlEncoder from re-encoding already-escaped content during rendering

Tests

  • Added unit tests verifying the Encode property is correctly set to false
  • Added integration tests covering capture + raw + escape filter combinations
  • All 1,315 existing tests continue to pass

The issue occurred because these filters HTML-encode their input but were returning StringValue instances with the default Encode = true, causing the renderer's HtmlEncoder to encode the output again.

Original prompt

This section details on the original issue you should resolve

<issue_title>Capturing encoded liquid tags</issue_title>
<issue_description>How to capture some liquid tag and rendering in html? The following code doesn't render what is expected:

{% capture r %}
{% raw %}
{% assign cultures = Culture | supported_cultures %}
<ul>item</ul>
{% endraw %}
{% endcapture %}
{{ r | escape }}

=>

{% assign cultures = Culture | supported_cultures %}
&amp;lt;ul&amp;gt;item&amp;lt;/ul&amp;gt;

This is double-encoded.

Without | escape it is not encoded at all.

{% assign cultures = Culture | supported_cultures %}
<ul>item</ul>

What is the way to get

{% assign cultures = Culture | supported_cultures %}
&lt;ul&gt;item&lt;/ul&gt;
```</issue_description>

<agent_instructions>Can you figure what is the issue, is the code not able to handle what is expected, or is there a way to do it?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

The escape and escape_once filters now return StringValue with Encode=false
to prevent double-encoding when rendered with HtmlEncoder. This fixes the
issue where captured raw content with escape filter was being double-encoded.

Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
@sebastienros
sebastienros marked this pull request as ready for review November 17, 2025 00:48
Copilot AI changed the title [WIP] Fix capturing of encoded liquid tags in HTML Fix double-encoding when using escape filter with HtmlEncoder Nov 17, 2025
Copilot AI requested a review from sebastienros November 17, 2025 00:49
@sebastienros
sebastienros enabled auto-merge (squash) November 17, 2025 00:49
@sebastienros
sebastienros merged commit 3c4a10f into main Nov 17, 2025
3 checks passed
@sebastienros
sebastienros deleted the copilot/fix-encoded-liquid-tags branch November 17, 2025 00:52
sebastienros added a commit that referenced this pull request Aug 20, 2026
* Initial plan

* Fix double-encoding issue with escape filter

The escape and escape_once filters now return StringValue with Encode=false
to prevent double-encoding when rendered with HtmlEncoder. This fixes the
issue where captured raw content with escape filter was being double-encoded.

Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee9c8775-0354-41dd-8226-89a69c60241c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capturing encoded liquid tags

2 participants