fix(block): respect current config when sanitizing labels#7674
fix(block): respect current config when sanitizing labels#7674cyphercodes wants to merge 1 commit intomermaid-js:developfrom
Conversation
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: cc75089 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@mermaid-js/examples
mermaid
@mermaid-js/layout-elk
@mermaid-js/layout-tidy-tree
@mermaid-js/mermaid-zenuml
@mermaid-js/parser
@mermaid-js/tiny
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7674 +/- ##
==========================================
- Coverage 3.33% 3.33% -0.01%
==========================================
Files 541 542 +1
Lines 56870 56879 +9
Branches 839 839
==========================================
Hits 1899 1899
- Misses 54971 54980 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
knsv-bot
left a comment
There was a problem hiding this comment.
[sisyphus-bot]
Thanks for the focused fix! This is a clean, minimal change that addresses #7622 at the root cause — and the regression test does a great job of demonstrating exactly the user-visible behavior the issue described.
What's working well
- 🎉 [praise] Right diagnosis, right fix. The
const config = getConfig()at module load was capturing a stale snapshot — replacing it with a per-callconfigApi.getConfig()is the correct fix and lets runtimedompurifyConfigupdates flow through tocommon.sanitizeTextas intended (blockDB.ts:18). - 🎉 [praise] The new test in
block.spec.tsis exactly the right shape — it setsFORBID_TAGS: ['b']after import and verifies<b>is stripped from the label. That's a tight regression test that maps directly to the bug report. - ✅ Changeset present, correctly scoped as
patchwith thefix(block-beta):prefix. - ✅ No XSS or sanitization concerns — the change strengthens the pipeline by honoring runtime config tightening rather than ignoring it. No new DOM sinks, attributes, or HTML construction are introduced; only the config source for the existing
common.sanitizeTextcall is updated.
Things to consider (non-blocking)
- 🟢 [nit] Convention consistency — most other diagram DBs (
classDb.ts:35,sankeyDB.ts:49,stateDb.ts,gitGraphAst.ts,ishikawaDb.ts) importgetConfigdirectly fromdiagram-api/diagramAPI.jsrather than going throughconfigApi.getConfig(). They're functionally identical (diagramAPIre-exports it), so this works either way — but keeping the existingimport { getConfig } from '../../diagram-api/diagramAPI.js'and just changing the body ofsanitizeTextto callgetConfig()would minimize the diff and stay consistent with neighboring diagrams. Totally fine to leave as-is if you prefer. - 🟢 [nit] In
block.spec.tsbeforeEach, theconfigApi.reset()afterconfigApi.setSiteConfig({})is redundant —setSiteConfigalready callsupdateCurrentConfiginternally (config.ts:80), so currentConfig is already in sync at that point. Harmless, just a touch of noise. - 💡 [suggestion] Worth considering a second test case that exercises a different
dompurifyConfigknob (e.g.,ADD_TAGSorFORBID_ATTR) to lock in the broader contract that the whole dompurify config is now respected at runtime, not justFORBID_TAGS. Not required for this PR — could land as a follow-up.
Nothing here is blocking — happy to see this go in. 🚀
📑 Summary
Fix block diagram label sanitization so it reads the current Mermaid config instead of a module-scope snapshot.
Resolves #7622
📏 Design Decisions
dompurifyConfigupdates are respected.dompurifyConfigafter import and verifies<b>labels are stripped.📋 Tasks