Skip to content

Commit

Permalink
Event: Avoid collisions between jQuery.event.special & Object.prototype
Browse files Browse the repository at this point in the history
This is a follow-up to similar changes to data & event storages from
gh-4603.

Closes gh-5235
Ref gh-4603
  • Loading branch information
mgol authored Apr 3, 2023
1 parent dfe212d commit bcaeb00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -494,7 +494,7 @@ jQuery.event = {
}
}
}
}
} )
};

// Ensure the presence of an event listener that handles manually-triggered
Expand Down
20 changes: 20 additions & 0 deletions test/unit/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( "<div></div>" )
.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 );
Expand Down

0 comments on commit bcaeb00

Please sign in to comment.