Permalink
Browse files

Event: Evaluate delegate selectors at add time

This ensures that invalid selectors throw right away.

Fixes gh-3071
Closes gh-3097
  • Loading branch information...
1 parent 931f45f commit 7fd36ea145a11d5896de6d064b546b1c57a83f34 @fsateler fsateler committed with gibson042 May 1, 2016
Showing with 18 additions and 0 deletions.
  1. +5 −0 src/event.js
  2. +13 −0 test/unit/event.js
View
@@ -120,6 +120,11 @@ jQuery.event = {
selector = handleObjIn.selector;
}
+ // If the selector is invalid, throw any exceptions at attach time
+ if ( selector ) {
+ jQuery.find( selector, elem );
+ }
+
// Make sure that the handler has a unique ID, used to find/remove it later
if ( !handler.guid ) {
handler.guid = jQuery.guid++;
View
@@ -1289,6 +1289,19 @@ QUnit.test( "Delegated events in SVG (#10791; #13180)", function( assert ) {
jQuery( "#qunit-fixture" ).off( "click" );
} );
+QUnit.test( "Delegated events with malformed selectors (#3071)", function( assert ) {
+ assert.expect( 2 );
+
+ assert.throws( function () {
+ jQuery( "#qunit-fixture" ).on( "click", "div:not", function () { } );
+ }, null, "malformed selector throws on attach" );
+
+ jQuery( "#qunit-fixture" ).click();
+ assert.ok( true, "malformed selector does not throw on event" );
+
+ jQuery( "#qunit-fixture" ).off( "click" );
+} );
+
QUnit.test( "Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) {
assert.expect( 5 );

0 comments on commit 7fd36ea

Please sign in to comment.