Skip to content

Commit

Permalink
Merge pull request #1286 from rofly/master
Browse files Browse the repository at this point in the history
fix: [#1285] Prevent contains from accessing properties of undefined args
  • Loading branch information
capricorn86 authored Mar 10, 2024
2 parents 3b4339d + 97833b3 commit 39d8c45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/happy-dom/src/nodes/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ export default class Node extends EventTarget implements INode {
* @param otherNode Node to test with.
* @returns "true" if this node contains the other node.
*/
public contains(otherNode: INode): boolean {
public contains(otherNode: INode | undefined): boolean {
if (otherNode === undefined) {
return false;
}
return NodeUtility.isInclusiveAncestor(this, otherNode);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/happy-dom/test/nodes/node/Node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ describe('Node', () => {

expect(div.contains(null)).toBe(false);
});
it('Returns "false" if match node is undefined.', () => {
const div = document.createElement('div');

expect(div.contains(undefined)).toBe(false);
});
});

describe('getRootNode()', () => {
Expand Down

0 comments on commit 39d8c45

Please sign in to comment.