aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2020-03-02 23:02:42 +0100
committerGitHub <noreply@github.com>2020-03-02 23:02:42 +0100
commit9d76c0b163675505d1a901e5fe5249a2c55609bc (patch)
tree33c4b3ec7a4d312b7db7f9ff1ef5ed21f15992c0 /test/unit
parent358b769a00c3a09a8ec621b8dcb2d5e31b7da69a (diff)
downloadjquery-9d76c0b163675505d1a901e5fe5249a2c55609bc.tar.gz
jquery-9d76c0b163675505d1a901e5fe5249a2c55609bc.zip
Data:Event:Manipulation: Prevent collisions with Object.prototype
Make sure events & data keys matching Object.prototype properties work. A separate fix for such events on cloned elements was added as well. Fixes gh-3256 Closes gh-4603
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/data.js15
-rw-r--r--test/unit/event.js43
2 files changed, 58 insertions, 0 deletions
diff --git a/test/unit/data.js b/test/unit/data.js
index 154ea5eeb..cba519e9e 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -998,3 +998,18 @@ QUnit.test( ".data(prop) does not create expando", function( assert ) {
}
}
} );
+
+QUnit.test( "keys matching Object.prototype properties (gh-3256)", function( assert ) {
+ assert.expect( 2 );
+
+ var div = jQuery( "<div/>" );
+
+ assert.strictEqual( div.data( "hasOwnProperty" ), undefined,
+ "hasOwnProperty not matched (before forced data creation)" );
+
+ // Force the creation of a data object for this element.
+ div.data( { foo: "bar" } );
+
+ assert.strictEqual( div.data( "hasOwnProperty" ), undefined,
+ "hasOwnProperty not matched (after forced data creation)" );
+} );
diff --git a/test/unit/event.js b/test/unit/event.js
index cecad3f34..938c66876 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -1796,6 +1796,49 @@ QUnit.test( "jQuery.off using dispatched jQuery.Event", function( assert ) {
.remove();
} );
+QUnit.test( "events with type matching an Object.prototype property (gh-3256)", function( assert ) {
+ assert.expect( 1 );
+
+ var elem = jQuery( "<div/>" ),
+ eventFired = false;
+
+ elem.appendTo( "#qunit-fixture" );
+
+ try {
+ elem
+ .one( "hasOwnProperty", function() {
+ eventFired = true;
+ } )
+ .trigger( "hasOwnProperty" );
+ } finally {
+ assert.strictEqual( eventFired, true, "trigger fired without crashing" );
+ }
+} );
+
+QUnit.test( "events with type matching an Object.prototype property, cloned element (gh-3256)",
+ function( assert ) {
+ assert.expect( 1 );
+
+ var elem = jQuery( "<div/>" ),
+ eventFired = false;
+
+ elem.appendTo( "#qunit-fixture" );
+
+ try {
+ // Make sure the original element has some event data.
+ elem.on( "click", function() {} );
+
+ elem
+ .clone( true )
+ .one( "hasOwnProperty", function() {
+ eventFired = true;
+ } )
+ .trigger( "hasOwnProperty" );
+ } finally {
+ assert.strictEqual( eventFired, true, "trigger fired without crashing" );
+ }
+} );
+
// selector-native does not support scope-fixing in delegation
QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "delegated event with delegateTarget-relative selector", function( assert ) {
assert.expect( 3 );