From: Dave Methvin Date: Thu, 9 May 2013 01:07:41 +0000 (-0400) Subject: Fix #13223. Re-allow leading space in HTML. Close gh-1264. X-Git-Tag: 2.0.1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9fdbc8bf33418f7b3a3a88df9a04ffee53c8dc66;p=jquery.git Fix #13223. Re-allow leading space in HTML. Close gh-1264. (cherry picked from commit 00eafdf028f7730665ce1c05ab44e3f0bc80fbc2) --- diff --git a/src/core.js b/src/core.js index 265f0bc4a..86b35a6f0 100644 --- a/src/core.js +++ b/src/core.js @@ -52,7 +52,7 @@ var // 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 <) - rquickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/, + rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, // Match a standalone tag rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, diff --git a/test/unit/core.js b/test/unit/core.js index 60b8e7272..7770000e5 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -38,7 +38,7 @@ test("jQuery()", function() { div = jQuery("

"), exec = false, lng = "", - expected = 20, + expected = 22, attrObj = { "text": "test", "class": "test2", @@ -113,6 +113,12 @@ test("jQuery()", function() { equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" ); + elem = jQuery(" hello")[0]; + equal( elem.nodeName.toLowerCase(), "em", "leading space" ); + + elem = jQuery("\n\nworld")[0]; + equal( elem.nodeName.toLowerCase(), "em", "leading newlines" ); + elem = jQuery("
", attrObj ); if ( jQuery.fn.width ) { diff --git a/test/unit/selector.js b/test/unit/selector.js index 440e7167b..7939ea350 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -73,18 +73,6 @@ test("disconnected nodes - jQuery only", function() { equal( $opt.is(":selected"), true, "selected option" ); }); -test("jQuery only - broken", 1, function() { - raises(function() { - // Setting context to null here somehow avoids QUnit's window.error handling - // making the e & e.message correct - // For whatever reason, without this, - // Sizzle.error will be called but no error will be seen in oldIE - jQuery.call( null, "
" ); - }, function( e ) { - return (/syntax.err/i).test( e.message ); - }, "leading space invalid: $('
')" ); -}); - testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQuery, window, document ) { expect( 35 );