Skip to content

Commit 4116914

Browse files
Krinkletimmywil
authored andcommitted
Core: Return empty array instead of null for parseHTML("")
Fixes jquerygh-1997 Close jquerygh-1998
1 parent d7e5fce commit 4116914

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
@@ -15,8 +15,8 @@ define([
1515
// defaults to document
1616
// keepScripts (optional): If true, will include scripts passed in the html string
1717
jQuery.parseHTML = function( data, context, keepScripts ) {
18-
if ( !data || typeof data !== "string" ) {
19-
return null;
18+
if ( typeof data !== "string" ) {
19+
return [];
2020
}
2121
if ( typeof context === "boolean" ) {
2222
keepScripts = context;

test/unit/core.js

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

13031303
test("jQuery.parseHTML", function() {
1304-
expect( 18 );
1304+
expect( 23 );
13051305

13061306
var html, nodes;
13071307

1308-
equal( jQuery.parseHTML(), null, "Nothing in, null out." );
1309-
equal( jQuery.parseHTML( null ), null, "Null in, null out." );
1310-
equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
1308+
deepEqual( jQuery.parseHTML(), [], "Without arguments" );
1309+
deepEqual( jQuery.parseHTML( undefined ), [], "Undefined" );
1310+
deepEqual( jQuery.parseHTML( null ), [], "Null" );
1311+
deepEqual( jQuery.parseHTML( false ), [], "Boolean false" );
1312+
deepEqual( jQuery.parseHTML( 0 ), [], "Zero" );
1313+
deepEqual( jQuery.parseHTML( true ), [], "Boolean true" );
1314+
deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" );
1315+
deepEqual( jQuery.parseHTML( "" ), [], "Empty string" );
13111316
throws(function() {
13121317
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
13131318
}, "Passing an element as the context raises an exception (context should be a document)");

0 commit comments

Comments
 (0)