Skip to content

Commit 36ce7ed

Browse files
committed
fix: [#1285] Prevent contains from accessing properties of undefined arguments
1 parent c127bc6 commit 36ce7ed

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/happy-dom/src/nodes/node/Node.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ export default class Node extends EventTarget implements INode {
298298
* @param otherNode Node to test with.
299299
* @returns "true" if this node contains the other node.
300300
*/
301-
public contains(otherNode: INode): boolean {
301+
public contains(otherNode: INode | undefined): boolean {
302+
if (otherNode === undefined) {
303+
return false;
304+
}
302305
return NodeUtility.isInclusiveAncestor(this, otherNode);
303306
}
304307

packages/happy-dom/test/nodes/node/Node.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ describe('Node', () => {
330330

331331
expect(div.contains(null)).toBe(false);
332332
});
333+
it('Returns "false" if match node is undefined.', () => {
334+
const div = document.createElement('div');
335+
336+
expect(div.contains(undefined)).toBe(false);
337+
});
333338
});
334339

335340
describe('getRootNode()', () => {

0 commit comments

Comments
 (0)