From 61bb61279ce51af189d40162dc62e44f04826051 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 7 Jan 2015 20:12:49 +0000 Subject: [PATCH] Core: Return empty array instead of null for parseHTML("") Fixes gh-1997 Close gh-1998 Conflicts: test/unit/core.js --- src/core/parseHTML.js | 4 ++-- test/unit/core.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index 2b638e633..1e41e50e8 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -14,8 +14,8 @@ define([ // defaults to document // keepScripts (optional): If true, will include scripts passed in the html string jQuery.parseHTML = function( data, context, keepScripts ) { - if ( !data || typeof data !== "string" ) { - return null; + if ( typeof data !== "string" ) { + return []; } if ( typeof context === "boolean" ) { keepScripts = context; diff --git a/test/unit/core.js b/test/unit/core.js index 370484b25..cbf5f7f2e 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1285,13 +1285,18 @@ test("jQuery.proxy", function(){ }); test("jQuery.parseHTML", function() { - expect( 17 ); + expect( 22 ); var html, nodes; - 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." ); + deepEqual( jQuery.parseHTML(), [], "Without arguments" ); + deepEqual( jQuery.parseHTML( undefined ), [], "Undefined" ); + deepEqual( jQuery.parseHTML( null ), [], "Null" ); + deepEqual( jQuery.parseHTML( false ), [], "Boolean false" ); + deepEqual( jQuery.parseHTML( 0 ), [], "Zero" ); + deepEqual( jQuery.parseHTML( true ), [], "Boolean true" ); + deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" ); + deepEqual( jQuery.parseHTML( "" ), [], "Empty string" ); throws(function() { jQuery.parseHTML( "
", document.getElementById("form") ); }, "Passing an element as the context raises an exception (context should be a document)"); -- 2.39.5