Core: Throw an error on $("#") rather than returning 0-length collection

Closes gh-1682

Thanks @goob for the issue report!
This commit is contained in:
Dave Methvin
2014-12-03 14:51:24 -05:00
parent cfe2eae38d
commit 80022c81ce
2 changed files with 9 additions and 3 deletions

View File

@@ -57,10 +57,15 @@ test("jQuery()", function() {
equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
// Invalid #id goes to Sizzle which will throw an error (gh-1682)
try {
jQuery( "#" );
} catch ( e ) {
ok( true, "Threw an error on #id with no id" );
}
// can actually yield more than one, when iframes are included, the window is an array as well
equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );