]> source.dussan.org Git - jquery.git/commitdiff
Fix #13203: delegated events with selector matching Object.prototype property
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 14 Jan 2013 02:38:40 +0000 (21:38 -0500)
committerRichard Gibson <richard.gibson@gmail.com>
Mon, 14 Jan 2013 02:40:24 +0000 (21:40 -0500)
src/event.js
test/unit/event.js

index a880bb64721e61e2c0872480c297ed4698295e09..0a85bf43c40fe242bdbb4dddaa1c4605e4eda6f4 100644 (file)
@@ -403,7 +403,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 ?
index 041920a533e9c202ad0ca42bf1bc75580317dd23..bc98f73cb5a23bb0384d492d669974f6f5eb3c7f 100644 (file)
@@ -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);