From f36f6abbb3e9e4d7d3729272ffb10b4c2c382919 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Mon, 9 Dec 2019 19:50:14 +0100 Subject: Event: Only attach events to objects that accept data - for real 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 d5c505e35d8c74ce8e9d99731a1a7eab0e0d911c) Fixes gh-4397 Closes gh-4558 --- test/unit/event.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/unit') diff --git a/test/unit/event.js b/test/unit/event.js index 17706a8b1..9a7692023 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2806,6 +2806,15 @@ QUnit.test( "preventDefault() on focusin does not throw exception", function( as }, QUnit.config.testTimeout / 4 || 1000 ); } ); +QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) { + assert.expect( 1 ); + + jQuery( document.createTextNode( "text" ) ) + .on( "focus", function() {} ); + + assert.ok( true, "No crash" ); +} ); + QUnit.test( "Donor event interference", function( assert ) { assert.expect( 8 ); -- cgit v1.2.3