From bbd453c0587b970cf714761fb1894231490bac93 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Fri, 13 Nov 2015 16:47:41 +0300 Subject: [PATCH] Revert "Core: Throw an error on $("#") rather than returning 0-length collection" This reverts commit 80022c81ce4a07a232afd3c580b0977555a2daec. --- src/core/init.js | 3 +-- test/unit/core.js | 9 ++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/core/init.js b/src/core/init.js index c4e1da33d..7748c38fb 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -12,8 +12,7 @@ var rootjQuery, // A simple way to check for HTML strings // Prioritize #id over to avoid XSS via location.hash (#9521) // Strict HTML recognition (#11290: must start with <) - // Shortcut simple #id case for speed - rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/, + rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, init = jQuery.fn.init = function( selector, context, root ) { var match, elem; diff --git a/test/unit/core.js b/test/unit/core.js index 694f66764..33a98cedc 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -56,14 +56,9 @@ QUnit.test( "jQuery()", function( assert ) { assert.equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); assert.equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); assert.equal( jQuery("").length, 0, "jQuery('') === jQuery([])" ); - assert.equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); + assert.equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" ); - // Invalid #id goes to Sizzle which will throw an error (gh-1682) - try { - jQuery( "#" ); - } catch ( e ) { - assert.ok( true, "Threw an error on #id with no id" ); - } + assert.equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); // can actually yield more than one, when iframes are included, the window is an array as well assert.equal( jQuery( window ).length, 1, "Correct number of elements generated for jQuery(window)" ); -- 2.39.5