From bcaeb000b777c018ad5d18e01be5060caa8cb158 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 3 Apr 2023 18:40:24 +0200 Subject: [PATCH] Event: Avoid collisions between jQuery.event.special & Object.prototype This is a follow-up to similar changes to data & event storages from gh-4603. Closes gh-5235 Ref gh-4603 --- src/event.js | 4 ++-- test/unit/event.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/event.js b/src/event.js index 7c9e1d546..5d2c8c1c3 100644 --- a/src/event.js +++ b/src/event.js @@ -429,7 +429,7 @@ jQuery.event = { new jQuery.Event( originalEvent ); }, - special: { + special: jQuery.extend( Object.create( null ), { load: { // Prevent triggered image.load events from bubbling to window.load @@ -494,7 +494,7 @@ jQuery.event = { } } } - } + } ) }; // Ensure the presence of an event listener that handles manually-triggered diff --git a/test/unit/event.js b/test/unit/event.js index 79057f191..920b2a182 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2428,6 +2428,26 @@ QUnit.test( ".on and .off, selective mixed removal (trac-10705)", function( asse .trigger( "click" ); // 0 } ); +QUnit.test( "special interference with Object.prototype", function( assert ) { + assert.expect( 1 ); + + var triggered = false; + + Object.prototype.jqfake = { + trigger: function() { + triggered = true; + } + }; + + jQuery( "
" ) + .appendTo( "#qunit-fixture" ) + .trigger( "jqfake" ); + + delete Object.prototype.jqfake; + + assert.ok( !triggered, "Object.prototype.jqfake.trigger not called" ); +} ); + QUnit.test( ".on( event-map, null-selector, data ) trac-11130", function( assert ) { assert.expect( 1 ); -- 2.39.5