-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Event: Only attach events to objects that accept data - for real #4558
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
Conversation
Wow, this does go back a ways! |
test/unit/event.js
Outdated
QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) { | ||
assert.expect( 1 ); | ||
|
||
jQuery( "<div></div>text<span></span>" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer something more obvious here such as jQuery( document.createTextNode("text") )
, but this works as long as the behavior doesn't change (do we test that, though?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gibson042 Your suggestion looks good to me. What do you mean by "as long as the behavior doesn't change", though? What behavior?
There was a check in jQuery.event.add that was supposed to make it a noop for objects that don't accept data like text or comment nodes. The problem was the check was incorrect: it assumed `dataPriv.get( elem )` returns a falsy value for an `elem` that doesn't accept data but that's not the case - we get an empty object then. The check was changed to use `acceptData` directly. Fixes jquerygh-4397
There was a check in jQuery.event.add that was supposed to make it a noop for objects that don't accept data like text or comment nodes. The problem was the check was incorrect: it assumed `dataPriv.get( elem )` returns a falsy value for an `elem` that doesn't accept data but that's not the case - we get an empty object then. The check was changed to use `acceptData` directly. (cherry picked from d5c505e) Fixes gh-4397 Closes gh-4558
Summary
There was a check in jQuery.event.add that was supposed to make it a noop
for objects that don't accept data like text or comment nodes. The problem was
the check was incorrect: it assumed
dataPriv.get( elem )
returns a falsyvalue for an
elem
that doesn't accept data but that's not the case - we getan empty object then. The check was changed to use
acceptData
directly.Fixes gh-4397
It's funny that this has been the behavior for at least the past few years so this code has been wrong for a long time. 😱
We'll also need to CP that to
3.x-stable
+2 bytes
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com