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

guard parentNode being null when walking DOM #54

Merged
merged 2 commits into from
Feb 18, 2015

Conversation

richardmonette
Copy link
Contributor

While walking the DOM it is possible that parentNode can become null. As a result, the not null check at line 53 may not guard against all null cases. This can be fixed by moving the check into the while loop conditions.

@tylermercier @celsodantas @nsimmons @patrickdonovan @kurtfunai @qq99

@nsimmons
Copy link
Contributor

Good catch 👍

@tylermercier
Copy link
Contributor

Can you add a test for this?

@qq99
Copy link
Contributor

qq99 commented Dec 19, 2014

May be tricky to add a test for this, perhaps detach the DOM node then trigger the event?


while target != document && (typeof target != "undefined")
while target != document && (typeof target != "undefined") && (target != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could be reduced to

while target != document && target?

which will compile to

while (target !== document && target != null)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rationale was that target != null will cause an error is target is not defined, whereas (I think anyways) that typeof target != "undefined" will return false even if target is not defined. Therefore, if target was undefined, or null, the checked would be false, an not in an error state. That being said, in this context I don't see how target would be undefined, so I agree with your solution. Updated in latest commit, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the future, typeof undefined == 'undefined' and typeof something_never_declared == 'undefined' and undefined == null

@richardmonette
Copy link
Contributor Author

@tylermercier @qq99 I'm going to have to refresh my memory after the holidays, but I'll work on getting a test for this.

@qq99
Copy link
Contributor

qq99 commented Feb 17, 2015

Can we ship this as is?

@nsimmons
Copy link
Contributor

I would :shipit:


while target != document && (typeof target != "undefined")
while target != document && target?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this can be just target and not target?

qq99 added a commit that referenced this pull request Feb 18, 2015
guard parentNode being null when walking DOM
@qq99 qq99 merged commit 78829dd into master Feb 18, 2015
@qq99 qq99 deleted the guard-parentnode-being-null branch February 18, 2015 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants