Skip to content

Commit fd42109

Browse files
authored
Core: Make jQuery.isXMLDoc accept falsy input
Fixes gh-4782 Closes gh-4814
1 parent dbcffb3 commit fd42109

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/core.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ jQuery.extend( {
307307
},
308308

309309
isXMLDoc: function( elem ) {
310-
var namespace = elem.namespaceURI,
311-
docElem = ( elem.ownerDocument || elem ).documentElement;
310+
var namespace = elem && elem.namespaceURI,
311+
docElem = elem && ( elem.ownerDocument || elem ).documentElement;
312312

313313
// Assume HTML when documentElement doesn't yet exist, such as inside
314314
// document fragments.

test/unit/core.js

+10
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ QUnit.test( "isXMLDoc - XML", function( assert ) {
417417
assert.ok( jQuery.isXMLDoc( jQuery( "desc", svg )[ 0 ] ), "XML desc Element" );
418418
} );
419419

420+
QUnit.test( "isXMLDoc - falsy", function( assert ) {
421+
assert.expect( 5 );
422+
423+
assert.strictEqual( jQuery.isXMLDoc( undefined ), false, "undefined" );
424+
assert.strictEqual( jQuery.isXMLDoc( null ), false, "null" );
425+
assert.strictEqual( jQuery.isXMLDoc( false ), false, "false" );
426+
assert.strictEqual( jQuery.isXMLDoc( 0 ), false, "0" );
427+
assert.strictEqual( jQuery.isXMLDoc( "" ), false, "\"\"" );
428+
} );
429+
420430
QUnit.test( "XSS via location.hash", function( assert ) {
421431
var done = assert.async();
422432
assert.expect( 1 );

0 commit comments

Comments
 (0)