Revert "Core: Return empty array instead of null for parseHTML("")"

This reverts commit 4116914dca.
This commit is contained in:
Oleg Gaidarenko 2015-11-13 16:21:08 +03:00
parent 3748c647f3
commit 7a78019751
2 changed files with 21 additions and 26 deletions

View File

@ -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;

View File

@ -1471,19 +1471,14 @@ QUnit.test( "jQuery.proxy", function( assert ) {
} );
QUnit.test("jQuery.parseHTML", function( assert ) {
assert.expect( 23 );
assert.expect( 18 );
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() {
assert.equal( jQuery.parseHTML(), null, "Nothing in, null out." );
assert.equal( jQuery.parseHTML( null ), null, "Null in, null out." );
assert.equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
throws(function() {
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
}, "Passing an element as the context raises an exception (context should be a document)");