mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "Core: Return empty array instead of null for parseHTML("")"
This reverts commit 61bb61279c
.
This commit is contained in:
parent
e73541dfe9
commit
7cfa4b26bc
@ -13,8 +13,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 ( typeof data !== "string" ) {
|
if ( !data || typeof data !== "string" ) {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
if ( typeof context === "boolean" ) {
|
if ( typeof context === "boolean" ) {
|
||||||
keepScripts = context;
|
keepScripts = context;
|
||||||
|
@ -1504,26 +1504,21 @@ QUnit.test( "jQuery.proxy", function( assert ) {
|
|||||||
cb.call( thisObject, "arg3" );
|
cb.call( thisObject, "arg3" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "jQuery.parseHTML", function( assert ) {
|
QUnit.test("jQuery.parseHTML", function( assert ) {
|
||||||
assert.expect( 22 );
|
expect( 17 );
|
||||||
|
|
||||||
var html, nodes;
|
var html, nodes;
|
||||||
|
|
||||||
assert.deepEqual( jQuery.parseHTML(), [], "Without arguments" );
|
equal( jQuery.parseHTML(), null, "Nothing in, null out." );
|
||||||
assert.deepEqual( jQuery.parseHTML( undefined ), [], "Undefined" );
|
equal( jQuery.parseHTML( null ), null, "Null in, null out." );
|
||||||
assert.deepEqual( jQuery.parseHTML( null ), [], "Null" );
|
equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
|
||||||
assert.deepEqual( jQuery.parseHTML( false ), [], "Boolean false" );
|
throws(function() {
|
||||||
assert.deepEqual( jQuery.parseHTML( 0 ), [], "Zero" );
|
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
|
||||||
assert.deepEqual( jQuery.parseHTML( true ), [], "Boolean true" );
|
}, "Passing an element as the context raises an exception (context should be a document)");
|
||||||
assert.deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" );
|
|
||||||
assert.deepEqual( jQuery.parseHTML( "" ), [], "Empty string" );
|
|
||||||
assert.throws( function() {
|
|
||||||
jQuery.parseHTML( "<div></div>", document.getElementById( "form" ) );
|
|
||||||
}, "Passing an element as the context raises an exception (context should be a document)" );
|
|
||||||
|
|
||||||
nodes = jQuery.parseHTML( jQuery( "body" )[ 0 ].innerHTML );
|
nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
|
||||||
assert.ok( nodes.length > 4, "Parse a large html string" );
|
ok( nodes.length > 4, "Parse a large html string" );
|
||||||
assert.equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
|
equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
|
||||||
|
|
||||||
html = "<script>undefined()</script>";
|
html = "<script>undefined()</script>";
|
||||||
assert.equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
|
assert.equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
|
||||||
|
Loading…
Reference in New Issue
Block a user