Skip to content

Commit

Permalink
fix: Avoid TypeError for null values on CUSTOM_ELEMENT_HANDLING config.
Browse files Browse the repository at this point in the history
ISSUE-897
  • Loading branch information
cpmotion committed Jan 5, 2024
1 parent 771eb82 commit 38e4dc3
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function clone(object) {
if (getOwnPropertyDescriptor(object, property) !== undefined) {
if (Array.isArray(value)) {
newObject[property] = cleanArray(value);
} else if (typeof value === 'object' && value.constructor === Object) {
} else if (value && typeof value === 'object' && value.constructor === Object) {
newObject[property] = clone(value);
} else {
newObject[property] = value;
Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ function clone(object) {
if (getOwnPropertyDescriptor(object, property) !== undefined) {
if (Array.isArray(value)) {
newObject[property] = cleanArray(value);
} else if (typeof value === 'object' && value.constructor === Object) {
} else if (
value &&
typeof value === 'object' &&
value.constructor === Object
) {
newObject[property] = clone(value);
} else {
newObject[property] = value;
Expand Down
15 changes: 15 additions & 0 deletions test/test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,21 @@
);
}
);
QUnit.test(
'CUSTOM_ELEMENT_HANDLING config values of null do not throw a TypeError.',
function (assert) {
DOMPurify.sanitize('', {
CUSTOM_ELEMENT_HANDLING: {
tagNameCheck: null,
attributeNameCheck: null,
allowCustomizedBuiltInElements: null,
},
});

// Don't see a great way to assert NOT throws...
assert.ok(true);
}
);
QUnit.test('Test dirty being an array', function (assert) {
assert.equal(
DOMPurify.sanitize(['<a>123<b>456</b></a>']),
Expand Down

0 comments on commit 38e4dc3

Please sign in to comment.