Skip to content

Commit f49a194

Browse files
committed
Update DOMPurify dependency
- Update to DOMPurify `3.2.1`, making `@types/dompurify` unnecessary. - Unfortunately, this change requires a type assertion for now.
1 parent 7c0d3ff commit f49a194

File tree

3 files changed

+18
-35
lines changed

3 files changed

+18
-35
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@
3232
"homepage": "https://github.com/CSS-Canvas/CSS-to-HTML#readme",
3333
"devDependencies": {
3434
"@playwright/test": "^1.48.0",
35-
"@types/dompurify": "^3.0.5",
3635
"@types/node": "^22.7.5",
3736
"typescript": "^5.6.3",
3837
"vite": "^5.4.9"
3938
},
4039
"dependencies": {
4140
"css-selector-parser": "^2.3.2",
42-
"dompurify": "^3.1.6"
41+
"dompurify": "^3.2.1"
4342
}
4443
}

src/Utility.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ export function replaceTextNode (element: HTMLElement | Element, value: string):
8888
* @returns A sanitized copy of the given element.
8989
*/
9090
export function sanitizeElement (element: HTMLElement): HTMLElement {
91-
const sanitizedElement = DOMPurify.sanitize(element, { RETURN_DOM: true });
92-
if (sanitizedElement instanceof HTMLBodyElement && !(element instanceof HTMLBodyElement)) {
93-
return sanitizedElement.firstElementChild as HTMLElement;
94-
}
91+
const sanitizedElement = element.cloneNode(true) as HTMLElement;
92+
DOMPurify.sanitize(sanitizedElement, { IN_PLACE: true });
9593
return sanitizedElement;
9694
}

0 commit comments

Comments
 (0)