mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Core: Return empty array instead of null for parseHTML("")
Fixes gh-1997 Close gh-1998
This commit is contained in:
parent
d7e5fcee51
commit
4116914dca
@ -15,8 +15,8 @@ define([
|
|||||||
// defaults to document
|
// defaults to document
|
||||||
// keepScripts (optional): If true, will include scripts passed in the html string
|
// keepScripts (optional): If true, will include scripts passed in the html string
|
||||||
jQuery.parseHTML = function( data, context, keepScripts ) {
|
jQuery.parseHTML = function( data, context, keepScripts ) {
|
||||||
if ( !data || typeof data !== "string" ) {
|
if ( typeof data !== "string" ) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
if ( typeof context === "boolean" ) {
|
if ( typeof context === "boolean" ) {
|
||||||
keepScripts = context;
|
keepScripts = context;
|
||||||
|
@ -1301,13 +1301,18 @@ test("jQuery.proxy", function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("jQuery.parseHTML", function() {
|
test("jQuery.parseHTML", function() {
|
||||||
expect( 18 );
|
expect( 23 );
|
||||||
|
|
||||||
var html, nodes;
|
var html, nodes;
|
||||||
|
|
||||||
equal( jQuery.parseHTML(), null, "Nothing in, null out." );
|
deepEqual( jQuery.parseHTML(), [], "Without arguments" );
|
||||||
equal( jQuery.parseHTML( null ), null, "Null in, null out." );
|
deepEqual( jQuery.parseHTML( undefined ), [], "Undefined" );
|
||||||
equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
|
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() {
|
throws(function() {
|
||||||
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
|
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
|
||||||
}, "Passing an element as the context raises an exception (context should be a document)");
|
}, "Passing an element as the context raises an exception (context should be a document)");
|
||||||
|
Loading…
Reference in New Issue
Block a user