Skip to content

Commit

Permalink
Fix #10844. Harden quickIs() against form-aliasing of the id property.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Nov 21, 2011
1 parent 1eb1ad6 commit 8cb065a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/event.js
Expand Up @@ -18,10 +18,11 @@ var rformElems = /^(?:textarea|input|select)$/i,
return quick; return quick;
}, },
quickIs = function( elem, m ) { quickIs = function( elem, m ) {
var attrs = elem.attributes || {};
return ( return (
(!m[1] || elem.nodeName.toLowerCase() === m[1]) && (!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
(!m[2] || elem.id === m[2]) && (!m[2] || (attrs.id || {}).value === m[2]) &&
(!m[3] || m[3].test( ((elem.attributes || {})[ "class" ] || {}).value )) (!m[3] || m[3].test( (attrs[ "class" ] || {}).value ))
); );
}, },
hoverHack = function( events ) { hoverHack = function( events ) {
Expand Down
23 changes: 23 additions & 0 deletions test/unit/event.js
Expand Up @@ -1209,6 +1209,29 @@ test("Delegated events in SVG (#10791)", function() {
svg.remove(); svg.remove();
}); });


test("Delegated events in forms (#10844)", function() {
expect(1);

// Aliases names like "id" cause havoc
var form = jQuery(
'<form id="myform">'+
'<input type="text" name="id" value="secret agent man" />'+
'</form>'
).appendTo( "body" );

jQuery( "body" )
.on( "submit", "#myform", function() {
ok( true, "delegated id selector with aliased name" );
return false;
})
.find( "#myform" )
.trigger( "submit" )
.end()
.off( "submit" );

form.remove();
});

test("jQuery.Event( type, props )", function() { test("jQuery.Event( type, props )", function() {


expect(5); expect(5);
Expand Down

0 comments on commit 8cb065a

Please sign in to comment.