Skip to content

Commit fd5858f

Browse files
committed
Revert "Core: Throw an error on $("#") rather than returning 0-length collection"
This reverts commit 93f95c9.
1 parent 9f2dcb9 commit fd5858f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/core/init.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ var rootjQuery,
1212
// A simple way to check for HTML strings
1313
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
1414
// Strict HTML recognition (#11290: must start with <)
15-
// Shortcut simple #id case for speed
16-
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
15+
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
1716

1817
init = jQuery.fn.init = function( selector, context, root ) {
1918
var match, elem;

test/unit/core.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,11 @@ QUnit.test( "jQuery()", function( assert ) {
5656
assert.expect( expected );
5757

5858
// Basic constructor's behavior
59-
assert.equal( jQuery().length, 0, "jQuery() === jQuery([])" );
60-
assert.equal( jQuery( undefined ).length, 0, "jQuery(undefined) === jQuery([])" );
61-
assert.equal( jQuery( null ).length, 0, "jQuery(null) === jQuery([])" );
62-
assert.equal( jQuery( "" ).length, 0, "jQuery('') === jQuery([])" );
63-
assert.deepEqual( jQuery( obj ).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );
64-
65-
// Invalid #id goes to Sizzle which will throw an error (gh-1682)
66-
try {
67-
jQuery( "#" );
68-
} catch ( e ) {
69-
assert.ok( true, "Threw an error on #id with no id" );
70-
}
59+
equal( jQuery().length, 0, "jQuery() === jQuery([])" );
60+
equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
61+
equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
62+
equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
63+
equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
7164

7265
// can actually yield more than one, when iframes are included, the window is an array as well
7366
assert.equal( jQuery( window ).length, 1, "Correct number of elements generated for jQuery(window)" );

0 commit comments

Comments
 (0)