diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2013-01-13 21:38:40 -0500 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2013-01-13 21:42:36 -0500 |
commit | 63f40866fdc9c74c7732084abca040ab06ebabde (patch) | |
tree | 1867d9c537712950be3cc1334697e97d32bad6d0 | |
parent | 0a3a424e65f66414305bf6a34fc6fd93d3b61c62 (diff) | |
download | jquery-63f40866fdc9c74c7732084abca040ab06ebabde.tar.gz jquery-63f40866fdc9c74c7732084abca040ab06ebabde.zip |
Fix #13203: delegated events with selector matching Object.prototype property
(cherry picked from commit 31b95797155077e4e670c0bbb2c57815f89769a1)
-rw-r--r-- | src/event.js | 4 | ||||
-rw-r--r-- | test/unit/event.js | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/event.js b/src/event.js index 6c0dc41ca..772d65ef4 100644 --- a/src/event.js +++ b/src/event.js @@ -415,7 +415,9 @@ jQuery.event = { matches = []; for ( i = 0; i < delegateCount; i++ ) { handleObj = handlers[ i ]; - sel = handleObj.selector; + + // Don't conflict with Object.prototype properties (#13203) + sel = handleObj.selector + " "; if ( matches[ sel ] === undefined ) { matches[ sel ] = handleObj.needsContext ? diff --git a/test/unit/event.js b/test/unit/event.js index 041920a53..bc98f73cb 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1797,6 +1797,20 @@ test( "delegated event with delegateTarget-relative selector", function() { markup.remove(); }); +test( "delegated event with selector matching Object.prototype property (#13203)", function() { + expect(1); + + var matched = 0; + + jQuery("#foo").on( "click", "toString", function( e ) { + matched++; + }); + + jQuery("#anchor2").trigger("click"); + + equal( matched, 0, "Nothing matched 'toString'" ); +}); + test("stopPropagation() stops directly-bound events on delegated target", function() { expect(1); |