Skip to content

Commit 363a89d

Browse files
author
yehuya
committed
fix: handle undefined Element in DOMPurify initialization
1 parent f41b45d commit 363a89d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/purify.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
125125
if (
126126
!window ||
127127
!window.document ||
128-
window.document.nodeType !== NODE_TYPE.document
128+
window.document.nodeType !== NODE_TYPE.document ||
129+
!window.Element
129130
) {
130131
// Not running in a browser, provide a factory function
131132
// so that you can pass your own Window

test/test-suite.js

+12
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,18 @@
870870
DOMPurify({ document: 'not really a document' }).sanitize,
871871
undefined
872872
);
873+
assert.strictEqual(
874+
typeof DOMPurify({ ...window, Element: undefined }).version,
875+
'string'
876+
);
877+
assert.strictEqual(
878+
DOMPurify({ ...window, Element: undefined }).isSupported,
879+
false
880+
);
881+
assert.strictEqual(
882+
DOMPurify({ ...window, Element: undefined }).sanitize,
883+
undefined
884+
);
873885
assert.strictEqual(typeof DOMPurify(window).version, 'string');
874886
assert.strictEqual(typeof DOMPurify(window).sanitize, 'function');
875887
});

0 commit comments

Comments
 (0)