From: Oleg Gaidarenko Date: Tue, 22 Dec 2015 18:01:43 +0000 (+0300) Subject: Revert "Core: Return empty array instead of null for parseHTML("")" X-Git-Tag: 1.12.0~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7cfa4b26bc96c07254ba036a3a957421e4e43786;p=jquery.git Revert "Core: Return empty array instead of null for parseHTML("")" This reverts commit 61bb61279ce51af189d40162dc62e44f04826051. --- diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index f6eb7abb4..55f67c43e 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -13,8 +13,8 @@ define( [ // defaults to document // keepScripts (optional): If true, will include scripts passed in the html string jQuery.parseHTML = function( data, context, keepScripts ) { - if ( typeof data !== "string" ) { - return []; + if ( !data || typeof data !== "string" ) { + return null; } if ( typeof context === "boolean" ) { keepScripts = context; diff --git a/test/unit/core.js b/test/unit/core.js index 84548a0df..9714b8685 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1504,26 +1504,21 @@ QUnit.test( "jQuery.proxy", function( assert ) { cb.call( thisObject, "arg3" ); } ); -QUnit.test( "jQuery.parseHTML", function( assert ) { - assert.expect( 22 ); +QUnit.test("jQuery.parseHTML", function( assert ) { + expect( 17 ); var html, nodes; - assert.deepEqual( jQuery.parseHTML(), [], "Without arguments" ); - assert.deepEqual( jQuery.parseHTML( undefined ), [], "Undefined" ); - assert.deepEqual( jQuery.parseHTML( null ), [], "Null" ); - assert.deepEqual( jQuery.parseHTML( false ), [], "Boolean false" ); - assert.deepEqual( jQuery.parseHTML( 0 ), [], "Zero" ); - assert.deepEqual( jQuery.parseHTML( true ), [], "Boolean true" ); - assert.deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" ); - assert.deepEqual( jQuery.parseHTML( "" ), [], "Empty string" ); - assert.throws( function() { - jQuery.parseHTML( "
", document.getElementById( "form" ) ); - }, "Passing an element as the context raises an exception (context should be a document)" ); + equal( jQuery.parseHTML(), null, "Nothing in, null out." ); + equal( jQuery.parseHTML( null ), null, "Null in, null out." ); + equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." ); + throws(function() { + jQuery.parseHTML( "
", document.getElementById("form") ); + }, "Passing an element as the context raises an exception (context should be a document)"); - nodes = jQuery.parseHTML( jQuery( "body" )[ 0 ].innerHTML ); - assert.ok( nodes.length > 4, "Parse a large html string" ); - assert.equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" ); + nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML ); + ok( nodes.length > 4, "Parse a large html string" ); + equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" ); html = ""; assert.equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );