Skip to content

Commit b4b10f3

Browse files
committed
Selector: Fix the Sizzle test for form#lengthtest
Also, add a test to jQuery that will actually test for this issue.
1 parent e76609c commit b4b10f3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/selector.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ function find( selector, context, results, seed ) {
200200
push.call( results, elem );
201201
return results;
202202
}
203+
} else {
204+
return results;
203205
}
204-
return results;
205206

206207
// Element context
207208
} else {

test/unit/selector.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ QUnit.test( "broken selectors throw", function( assert ) {
227227
} );
228228

229229
QUnit.test( "id", function( assert ) {
230-
assert.expect( 34 );
230+
assert.expect( 35 );
231231

232-
var fiddle, a;
232+
var fiddle, a, lengthtest;
233233

234234
assert.t( "ID Selector", "#body", [ "body" ] );
235235
assert.t( "ID Selector w/ Element", "body#body", [ "body" ] );
@@ -288,6 +288,15 @@ QUnit.test( "id", function( assert ) {
288288

289289
assert.t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", [ "lengthtest" ] );
290290

291+
// Run the above test again but with `jQuery.find` directly to avoid the jQuery
292+
// quick path that avoids running the selector engine.
293+
lengthtest = jQuery.find( "#lengthtest" );
294+
assert.strictEqual(
295+
lengthtest && lengthtest[ 0 ],
296+
document.getElementById( "lengthtest" ),
297+
"ID Selector on Form with an input that has a name of 'id' - no quick path (#lengthtest)"
298+
);
299+
291300
assert.t( "ID selector with non-existent ancestor", "#asdfasdf #foobar", [] ); // bug trac-986
292301

293302
assert.deepEqual( jQuery.find( "div#form", document.body ), [],

0 commit comments

Comments
 (0)