Skip to content

Commit 61bb612

Browse files
Krinkletimmywil
authored andcommitted
Core: Return empty array instead of null for parseHTML("")
Fixes gh-1997 Close gh-1998 Conflicts: test/unit/core.js
1 parent 30ace26 commit 61bb612

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/core/parseHTML.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ define([
1414
// defaults to document
1515
// keepScripts (optional): If true, will include scripts passed in the html string
1616
jQuery.parseHTML = function( data, context, keepScripts ) {
17-
if ( !data || typeof data !== "string" ) {
18-
return null;
17+
if ( typeof data !== "string" ) {
18+
return [];
1919
}
2020
if ( typeof context === "boolean" ) {
2121
keepScripts = context;

test/unit/core.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,13 +1285,18 @@ test("jQuery.proxy", function(){
12851285
});
12861286

12871287
test("jQuery.parseHTML", function() {
1288-
expect( 17 );
1288+
expect( 22 );
12891289

12901290
var html, nodes;
12911291

1292-
equal( jQuery.parseHTML(), null, "Nothing in, null out." );
1293-
equal( jQuery.parseHTML( null ), null, "Null in, null out." );
1294-
equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
1292+
deepEqual( jQuery.parseHTML(), [], "Without arguments" );
1293+
deepEqual( jQuery.parseHTML( undefined ), [], "Undefined" );
1294+
deepEqual( jQuery.parseHTML( null ), [], "Null" );
1295+
deepEqual( jQuery.parseHTML( false ), [], "Boolean false" );
1296+
deepEqual( jQuery.parseHTML( 0 ), [], "Zero" );
1297+
deepEqual( jQuery.parseHTML( true ), [], "Boolean true" );
1298+
deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" );
1299+
deepEqual( jQuery.parseHTML( "" ), [], "Empty string" );
12951300
throws(function() {
12961301
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
12971302
}, "Passing an element as the context raises an exception (context should be a document)");

0 commit comments

Comments
 (0)