Skip to content

Commit 9fdbc8b

Browse files
committed
Fix #13223. Re-allow leading space in HTML. Close jquerygh-1264.
(cherry picked from commit 00eafdf)
1 parent c9267ab commit 9fdbc8b

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var
5252
// A simple way to check for HTML strings
5353
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
5454
// Strict HTML recognition (#11290: must start with <)
55-
rquickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,
55+
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
5656

5757
// Match a standalone tag
5858
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,

test/unit/core.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test("jQuery()", function() {
3838
div = jQuery("<div/><hr/><code/><b/>"),
3939
exec = false,
4040
lng = "",
41-
expected = 20,
41+
expected = 22,
4242
attrObj = {
4343
"text": "test",
4444
"class": "test2",
@@ -113,6 +113,12 @@ test("jQuery()", function() {
113113

114114
equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
115115

116+
elem = jQuery(" <em>hello</em>")[0];
117+
equal( elem.nodeName.toLowerCase(), "em", "leading space" );
118+
119+
elem = jQuery("\n\n<em>world</em>")[0];
120+
equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
121+
116122
elem = jQuery("<div/>", attrObj );
117123

118124
if ( jQuery.fn.width ) {

test/unit/selector.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ test("disconnected nodes - jQuery only", function() {
7373
equal( $opt.is(":selected"), true, "selected option" );
7474
});
7575

76-
test("jQuery only - broken", 1, function() {
77-
raises(function() {
78-
// Setting context to null here somehow avoids QUnit's window.error handling
79-
// making the e & e.message correct
80-
// For whatever reason, without this,
81-
// Sizzle.error will be called but no error will be seen in oldIE
82-
jQuery.call( null, " <div/> " );
83-
}, function( e ) {
84-
return (/syntax.err/i).test( e.message );
85-
}, "leading space invalid: $(' <div/> ')" );
86-
});
87-
8876
testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQuery, window, document ) {
8977
expect( 35 );
9078

0 commit comments

Comments
 (0)