Skip to content

Commit

Permalink
Core: Make Sizzle.isXML accept falsy input
Browse files Browse the repository at this point in the history
  • Loading branch information
mgol committed Dec 1, 2020
1 parent 390f240 commit e377b1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ support = Sizzle.support = {};
* @returns {Boolean} True iff elem is a non-HTML XML node
*/
isXML = Sizzle.isXML = function( elem ) {
var namespace = elem.namespaceURI,
docElem = ( elem.ownerDocument || elem ).documentElement;
var namespace = elem && elem.namespaceURI,
docElem = elem && ( elem.ownerDocument || elem ).documentElement;

// Support: IE <=8
// Assume HTML when documentElement doesn't yet exist, such as inside loading iframes
Expand Down
8 changes: 7 additions & 1 deletion test/unit/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ if ( jQuery( "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' w
}

QUnit.test( "Sizzle.isXML", function( assert ) {
assert.expect( 10 );
assert.expect( 15 );

var svgTree,
xmlTree = jQuery.parseXML( "<docElem><elem/></docElem>" ).documentElement,
Expand Down Expand Up @@ -255,6 +255,12 @@ QUnit.test( "Sizzle.isXML", function( assert ) {
} else {
assert.ok( true, "Cannot test an incomplete DOM" );
}

assert.strictEqual( jQuery.isXMLDoc( undefined ), false, "undefined" );
assert.strictEqual( jQuery.isXMLDoc( null ), false, "null" );
assert.strictEqual( jQuery.isXMLDoc( false ), false, "false" );
assert.strictEqual( jQuery.isXMLDoc( 0 ), false, "0" );
assert.strictEqual( jQuery.isXMLDoc( "" ), false, "\"\"" );
} );

QUnit.test( "Sizzle.uniqueSort", function( assert ) {
Expand Down

0 comments on commit e377b1c

Please sign in to comment.