mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Evaluate delegate selectors at add time
This ensures that invalid selectors throw right away. Fixes gh-3071 Closes gh-3097
This commit is contained in:
parent
931f45fc38
commit
7fd36ea145
@ -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++;
|
||||
|
@ -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 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user