-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mindmap): correctly render ampersand (&) #6315
base: develop
Are you sure you want to change the base?
fix(mindmap): correctly render ampersand (&) #6315
Conversation
|
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
commit: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6315 +/- ##
=======================================
Coverage 3.89% 3.89%
=======================================
Files 398 397 -1
Lines 41966 41958 -8
Branches 637 637
=======================================
Hits 1634 1634
+ Misses 40332 40324 -8
Flags with carried forward coverage won't be shown. Click here to find out more.
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
I also investigated this issue, and this code seems to work. In my opinion, the following code has less impact on other diagrams and less likely to introduce vulnerability. SuggestionChange const node = {
id: cnt++,
nodeId: sanitizeText(id, conf),
level,
descr: sanitizeText(descr, conf)
+ .replace(/&/g, '&')
+ .replace(/>/g, '>') // Those characters cannot be rendered as expected too!
+ .replace(/</g, '<'),
type,
children: [],
width: conf.mindmap?.maxNodeWidth ?? defaultConfig.mindmap.maxNodeWidth,
padding,
} satisfies MindmapNode; This code is part of the process that parses raw mermaid mindmap code. HTML special characters are escaped here, and they are passed to D3.Selection.text, so the rendered text remains escaped. This approach is also used in let sanitizedText = sanitizeText(text.text, getConfig());
sanitizedText = sanitizedText.replace(/=/g, '=');
sanitizedText = sanitizedText.replace(/&/g, '&'); It fixes the problem in my environment, at least. I hope this helps. |
📑 Summary
Fixes an issue where ampersands (&) were not rendering properly in Mindmap nodes. This was caused by using .text(description), which escapes special characters, instead of .html(description).
Resolves #6308
📏 Design Decisions
Issue: When rendering text inside Mindmap nodes, .text() was escaping special characters like &, causing them to display incorrectly.
Solution: Updated createText.ts to use .html(description) instead of .text(description), ensuring proper rendering.
Impact: This fix allows ampersands (&) and other special HTML characters to be displayed correctly without breaking existing functionality.
📋 Tasks
Make sure you
MERMAID_RELEASE_VERSION
is used for all new features.pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.