Skip to content

Commit 8cb065a

Browse files
committed
Fix #10844. Harden quickIs() against form-aliasing of the id property.
1 parent 1eb1ad6 commit 8cb065a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/event.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ var rformElems = /^(?:textarea|input|select)$/i,
1818
return quick;
1919
},
2020
quickIs = function( elem, m ) {
21+
var attrs = elem.attributes || {};
2122
return (
2223
(!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
23-
(!m[2] || elem.id === m[2]) &&
24-
(!m[3] || m[3].test( ((elem.attributes || {})[ "class" ] || {}).value ))
24+
(!m[2] || (attrs.id || {}).value === m[2]) &&
25+
(!m[3] || m[3].test( (attrs[ "class" ] || {}).value ))
2526
);
2627
},
2728
hoverHack = function( events ) {

test/unit/event.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,29 @@ test("Delegated events in SVG (#10791)", function() {
12091209
svg.remove();
12101210
});
12111211

1212+
test("Delegated events in forms (#10844)", function() {
1213+
expect(1);
1214+
1215+
// Aliases names like "id" cause havoc
1216+
var form = jQuery(
1217+
'<form id="myform">'+
1218+
'<input type="text" name="id" value="secret agent man" />'+
1219+
'</form>'
1220+
).appendTo( "body" );
1221+
1222+
jQuery( "body" )
1223+
.on( "submit", "#myform", function() {
1224+
ok( true, "delegated id selector with aliased name" );
1225+
return false;
1226+
})
1227+
.find( "#myform" )
1228+
.trigger( "submit" )
1229+
.end()
1230+
.off( "submit" );
1231+
1232+
form.remove();
1233+
});
1234+
12121235
test("jQuery.Event( type, props )", function() {
12131236

12141237
expect(5);

0 commit comments

Comments
 (0)