Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.contains doesn't handle undefined args #1285

Closed
rofly opened this issue Mar 1, 2024 · 0 comments
Closed

Node.contains doesn't handle undefined args #1285

rofly opened this issue Mar 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rofly
Copy link
Contributor

rofly commented Mar 1, 2024

Describe the bug

Calling Node.contains with undefined argument raises a TypeError exception.

"TypeError": Cannot read properties of undefined (reading 'Symbol(parentNode)')

To Reproduce

Run the following code snippet

const happyDom = require("happy-dom");

const happyWindow = new happyDom.Window();
const parentElement = happyWindow.document.createElement('div');
const childElement = happyWindow.document.createElement('div');

parentElement.appendChild(childElement);

let nonInitializedElement;

parentElement.contains(nonInitializedElement);

Expected behavior

The same behavior that happens in the browser.
Node.contains should return false when it's called with undefined

@rofly rofly added the bug Something isn't working label Mar 1, 2024
rofly added a commit to rofly/happy-dom that referenced this issue Mar 1, 2024
rofly added a commit to rofly/happy-dom that referenced this issue Mar 1, 2024
capricorn86 added a commit that referenced this issue Mar 10, 2024
fix: [#1285] Prevent contains from accessing properties of undefined args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants