Fix: Properly decode <, >, and & in mindmap node labels#6406
Fix: Properly decode <, >, and & in mindmap node labels#6406BambioGaming wants to merge 6 commits intomermaid-js:developfrom
Conversation
|
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6406 +/- ##
=======================================
Coverage 3.86% 3.86%
=======================================
Files 412 411 -1
Lines 43189 43184 -5
Branches 664 664
=======================================
Hits 1670 1670
+ Misses 41519 41514 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
…bug/6396_mindmap-decode
…ming/mermaid into bug/6396_mindmap-decode
6360dd7 to
d9335ea
Compare
|
I’ve confirmed that |
|
[sisyphus-bot] Thanks for the clean fix, @BambioGaming — the intent here makes sense and the implementation is close. One important correction though: extending decodeEntities() is not the right place to solve this, and it can be security-sensitive. In our current pipeline we can end up calling decodeEntities() multiple times and sometimes after sanitizeText(). That means decoding additional sequences (including nested/encoded forms like &lt;) risks re-introducing markup after sanitization and could open an XSS footgun if anything slips past DOMPurify. Could you please update the PR to avoid expanding decodeEntities() and instead address decoding in a way that preserves the invariant: Before we can merge, could you please: Appreciate the contribution — this is a subtle edge case and your work is definitely moving it forward. P.S. This comment was generated with the help of an AI assistant and may be wrong; please sanity-check the review feedback against the code + Argos output. |
When creating labels using `htmlLabels: false`, e.g.
```mermaid
---
config:
htmlLabels: false
---
flowchart TD
A[2 < 4 && 12 > 14]
```
The SVG node label gets rendered as
`2 < 4 && 12 > 14`. This is fine for HTML text, where we
use `.innerHTML` to set the value. But for non-HTML Labels, we use
`.textContent`, so we need to pass the unescaped values.
Ideally we would stop calling DOMPurify on this label when
`.textContent` is used, since the content doesn't need to be sanitized,
but adding a quick `<`/`>`/`&`-> `<`/`>`/`&` also works.
I've adapted this commit from mermaid-js#6406.
Closes: mermaid-js#6406
Co-authored-by: khalil <5alil.landolsi@gmail.com>
When creating labels using `htmlLabels: false`, e.g.
```mermaid
---
config:
htmlLabels: false
---
flowchart TD
A[2 < 4 && 12 > 14]
```
The SVG node label gets rendered as
`2 < 4 && 12 > 14`. This is fine for HTML text, where we
use `.innerHTML` to set the value. But for non-HTML Labels, we use
`.textContent`, so we need to pass the unescaped values.
Ideally we would stop calling DOMPurify on this label when
`.textContent` is used, since the content doesn't need to be sanitized,
but adding a quick `<`/`>`/`&`-> `<`/`>`/`&` also works.
I've adapted this commit from mermaid-js#6406
and from mermaid-js#7039
Closes: mermaid-js#6406
Co-authored-by: khalil <5alil.landolsi@gmail.com>
Co-authored-by: Samarth <115448290+SAMARTHAGARWAL77@users.noreply.github.com>
📑 Summary
This pull request fixes a rendering bug in Mermaid mindmap diagrams where characters like
<,>, and&were incorrectly displayed as<,>, and&inside SVG elements.This issue occurred because
.text()in D3/SVG escapes HTML entities even when the decoded content is passed in. This PR addresses it by decoding these entities right before rendering.Resolves #6396
📏 Design Decisions
Modified
decodeEntities()function inutils.tsto replace common HTML entities (<, >, &) with their correct characters.Applied
decodeEntities()immediately before inserting text content into<tspan>elements via.text()in theupdateTextContentAndStyles()function ofcreateText.ts.This approach ensures that the final text rendered in the SVG node is accurate and unescaped while maintaining full safety.
Screenshots
Before

After

📋 Tasks
Make sure you
MERMAID_RELEASE_VERSIONis used for all new features.pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.