Skip to content

Fix double-escaped entities in renderAsPlaintext code spans#320336

Draft
roblourens wants to merge 1 commit into
mainfrom
roblou/fix-plaintext-codespan-escape
Draft

Fix double-escaped entities in renderAsPlaintext code spans#320336
roblourens wants to merge 1 commit into
mainfrom
roblou/fix-plaintext-codespan-escape

Conversation

@roblourens
Copy link
Copy Markdown
Member

@roblourens roblourens commented Jun 8, 2026

For #303752

I think this is ok but please take a quick look @mjbvz

Problem

Text inside markdown code spans (e.g. foo & bar) rendered through renderAsPlaintext came out double-escaped& appeared as &amp;, </> as &lt;/&gt;. This surfaced in the agent sessions list, where a local (VS Code harness) session's in-progress description is derived from a tool invocation message via getInProgressSessionDescriptionrenderAsPlaintext.

Root cause

In createPlainTextRenderer, the codespan handler called escape(text). But marked already HTML-escapes code span text during tokenization. The trailing unescape pass in renderAsPlaintext only reverses a single level, so the extra escape() left entities double-escaped. Code blocks were unaffected because marked passes their text raw (escaped exactly once).

Input Before After
Run \tests & build`` Run tests &amp; build Run tests & build
Use \`` Use &lt;form&gt; Use <form>

Fix

Remove the redundant escape() from the codespan plaintext renderer so it matches code-block behavior. Added a regression test.

This is a shared low-level helper, so the fix corrects the same double-escaping for all renderAsPlaintext callers (hovers, pickers, etc.), not just the agent sessions list.

(Written by Copilot)

The plaintext markdown renderer's codespan handler called escape() on text
that marked had already HTML-escaped during tokenization. The trailing
unescape pass in renderAsPlaintext only reverses one level, so entities
inside code spans leaked through double-escaped (e.g. & -> &amp;, < -> &lt;).
Removing the redundant escape() makes code spans match code-block behavior.

(Written by Copilot)
Copilot AI review requested due to automatic review settings June 8, 2026 01:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes renderAsPlaintext producing double-escaped HTML entities inside Markdown inline code spans (`...`) by removing an extra escaping step in the plaintext renderer, aligning code span handling with marked’s own token escaping.

Changes:

  • Stop re-escaping marked codespan token text in createPlainTextRenderer to prevent double-escaped entities.
  • Add a regression test ensuring entities/HTML-like content in code spans renders as expected in plaintext output.
Show a summary per file
File Description
src/vs/base/browser/markdownRenderer.ts Removes redundant escaping in the plaintext codespan renderer to avoid double-escaped entities.
src/vs/base/test/browser/markdownRenderer.test.ts Adds a regression test covering plaintext rendering of code spans containing escapable characters/entities.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread src/vs/base/test/browser/markdownRenderer.test.ts
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.

2 participants