Skip to content

Commit

Permalink
fix: [capricorn86#1285] Prevent contains from accessing properties of…
Browse files Browse the repository at this point in the history
… undefined arguments
  • Loading branch information
rofly committed Mar 1, 2024
1 parent c127bc6 commit 5051cf0
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 @@ -298,7 +298,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 @@ -328,6 +328,11 @@ describe('Node', () => {
it('Returns "false" if match node is null.', () => {
const div = document.createElement('div');

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

expect(div.contains(null)).toBe(false);
});
});
Expand Down

0 comments on commit 5051cf0

Please sign in to comment.