]> source.dussan.org Git - jquery.git/commitdiff
Event: Avoid collisions between jQuery.event.special & Object.prototype
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 3 Apr 2023 16:40:24 +0000 (18:40 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Apr 2023 16:40:24 +0000 (18:40 +0200)
This is a follow-up to similar changes to data & event storages from
gh-4603.

Closes gh-5235
Ref gh-4603

src/event.js
test/unit/event.js

index 7c9e1d546bda7a688483d95e82e7c1d6a5c7bac8..5d2c8c1c3c12c171c571f84a80c6b7d410b73ed3 100644 (file)
@@ -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
index 79057f19126c27a433830291e8e61d019f21e8b7..920b2a182d3e2d1774797619e6330bfdeeb08167 100644 (file)
@@ -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 );