Skip to content

Commit dfaaf36

Browse files
Merge pull request #6079 from aloisklink/chore/update-to-dompurify-3.2.1
fix: update dompurify to `^3.2.1` and remove `@types/dompurify`
2 parents d3b2c7e + fe3cffb commit dfaaf36

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

Diff for: .changeset/neat-rabbits-bake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mermaid': patch
3+
---
4+
5+
Bump dompurify to `^3.2.1`. This removes the need for `@types/dompurify`.

Diff for: packages/mermaid/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@
7171
"@iconify/utils": "^2.1.32",
7272
"@mermaid-js/parser": "workspace:^",
7373
"@types/d3": "^7.4.3",
74-
"@types/dompurify": "^3.0.5",
7574
"cytoscape": "^3.29.2",
7675
"cytoscape-cose-bilkent": "^4.1.0",
7776
"cytoscape-fcose": "^2.2.0",
7877
"d3": "^7.9.0",
7978
"d3-sankey": "^0.12.3",
8079
"dagre-d3-es": "7.0.11",
8180
"dayjs": "^1.11.10",
82-
"dompurify": "^3.0.11 <3.1.7",
81+
"dompurify": "^3.2.1",
8382
"katex": "^0.16.9",
8483
"khroma": "^2.1.0",
8584
"lodash-es": "^4.17.21",

Diff for: packages/mermaid/src/diagrams/common/common.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ const setupDompurifyHooksIfNotSetup = (() => {
3232
function setupDompurifyHooks() {
3333
const TEMPORARY_ATTRIBUTE = 'data-temp-href-target';
3434

35-
DOMPurify.addHook('beforeSanitizeAttributes', (node: Element) => {
36-
if (node.tagName === 'A' && node.hasAttribute('target')) {
35+
DOMPurify.addHook('beforeSanitizeAttributes', (node) => {
36+
if (node instanceof Element && node.tagName === 'A' && node.hasAttribute('target')) {
3737
node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') ?? '');
3838
}
3939
});
4040

41-
DOMPurify.addHook('afterSanitizeAttributes', (node: Element) => {
42-
if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
41+
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
42+
if (node instanceof Element && node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
4343
node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) ?? '');
4444
node.removeAttribute(TEMPORARY_ATTRIBUTE);
4545
if (node.getAttribute('target') === '_blank') {
@@ -83,7 +83,6 @@ export const sanitizeText = (text: string, config: MermaidConfig): string => {
8383
return text;
8484
}
8585
if (config.dompurifyConfig) {
86-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
8786
text = DOMPurify.sanitize(sanitizeMore(text, config), config.dompurifyConfig).toString();
8887
} else {
8988
text = DOMPurify.sanitize(sanitizeMore(text, config), {

Diff for: packages/mermaid/src/mermaidAPI.ts

+1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ const render = async function (
455455
svgCode = DOMPurify.sanitize(svgCode, {
456456
ADD_TAGS: DOMPURIFY_TAGS,
457457
ADD_ATTR: DOMPURIFY_ATTR,
458+
HTML_INTEGRATION_POINTS: { foreignobject: true },
458459
});
459460
}
460461

Diff for: pnpm-lock.yaml

+8-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/tsc-check.ts

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const SRC = {
3838
// to match the real `package.json` values
3939
'type-fest': '*',
4040
'@types/d3': '^7.4.3',
41-
'@types/dompurify': '^3.0.5',
4241
typescript: '*',
4342
},
4443
},

0 commit comments

Comments
 (0)