Skip to content

Commit e682fe6

Browse files
committed
Fix DOMPurify error
1 parent 77cdee6 commit e682fe6

File tree

6 files changed

+4
-147
lines changed

6 files changed

+4
-147
lines changed

client/src/markdown-converter-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DOMPurify from "isomorphic-dompurify";
44
export class MarkdownConverterClient extends MarkdownConverter {
55
private static instance: MarkdownConverterClient;
66

7-
protected override dompurify = DOMPurify();
7+
protected override sanitize = (s: string, config: { ADD_TAGS: string[]; ADD_ATTR: string[] }) => DOMPurify.sanitize(s);
88

99
private constructor() {
1010
super((url: string) => fetch(url).then((it) => it.text()));

common/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dependencies": {
1313
"highlight.js": "10.7.3",
1414
"isomorphic-dompurify": "2.26.0",
15-
"jsdom": "25.0.0",
1615
"marked": "14.1.2",
1716
"marked-highlight": "2.1.4",
1817
"marked-mangle": "1.1.9",

common/src/markdown-converter-common.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DataUrl } from "@common/util/base64.js";
22
import { Buffer } from "buffer";
3-
import { DOMPurify } from "dompurify";
43
import highlightjs from "highlight.js";
54
import { marked, MarkedExtension, Token, Tokens } from "marked";
65
import { markedHighlight } from "marked-highlight";
@@ -91,7 +90,7 @@ export abstract class MarkdownConverter {
9190
};
9291
};
9392

94-
protected abstract dompurify: DOMPurify;
93+
protected abstract sanitize: (s: string, config: { ADD_TAGS: string[]; ADD_ATTR: string[] }) => string;
9594

9695
/**
9796
*
@@ -232,7 +231,7 @@ export abstract class MarkdownConverter {
232231
async: true,
233232
})
234233
.then((parsedInput) =>
235-
this.dompurify.sanitize(parsedInput, {
234+
this.sanitize(parsedInput, {
236235
// Allowed tags and attributes inside markdown
237236
ADD_TAGS: ["iframe", "foreignObject"], // foreignObject is needed for SVGs that show html tags inside them like mermaid-diagrams
238237
ADD_ATTR: ["allow", "allowfullscreen", "frameborder", "scrolling"],

package-lock.json

Lines changed: 0 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/check-packages.mts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import fs from "fs";
22
import path from "path";
3-
import { fileURLToPath } from "url";
4-
import { dirname } from "path";
5-
const __filename = fileURLToPath(import.meta.url);
6-
const __dirname = dirname(__filename);
73

84
let numFoundErrors = 0;
95

server/src/markdown-converter-server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { MarkdownConverter } from "@fumix/fu-blog-common";
22
import DOMPurify from "isomorphic-dompurify";
3-
import { JSDOM } from "jsdom";
43
import fetch from "node-fetch";
54

65
export class MarkdownConverterServer extends MarkdownConverter {
@@ -10,7 +9,7 @@ export class MarkdownConverterServer extends MarkdownConverter {
109
* On the server side, we need to pass a new window object to DOMPurify.
1110
* It doesn't work to just call `DOMPurify.sanitize()` directly like on the client side.
1211
*/
13-
protected override dompurify: DOMPurify.DOMPurify = DOMPurify.default(new JSDOM("").window);
12+
protected override sanitize = (s: string, config: { ADD_TAGS: string[]; ADD_ATTR: string[] }) => DOMPurify.sanitize(s, config);
1413

1514
private constructor() {
1615
super((url: string) => fetch(url).then((it) => it.text()));

0 commit comments

Comments
 (0)