Core: Make jQuery.isXMLDoc accept falsy input

Fixes gh-4782
Closes gh-4814
This commit is contained in:
Michał Gołębiowski-Owczarek 2020-12-07 21:09:15 +01:00 committed by GitHub
parent dbcffb396c
commit fd421097c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -307,8 +307,8 @@ jQuery.extend( {
}, },
isXMLDoc: function( elem ) { isXMLDoc: function( elem ) {
var namespace = elem.namespaceURI, var namespace = elem && elem.namespaceURI,
docElem = ( elem.ownerDocument || elem ).documentElement; docElem = elem && ( elem.ownerDocument || elem ).documentElement;
// Assume HTML when documentElement doesn't yet exist, such as inside // Assume HTML when documentElement doesn't yet exist, such as inside
// document fragments. // document fragments.

View File

@ -417,6 +417,16 @@ QUnit.test( "isXMLDoc - XML", function( assert ) {
assert.ok( jQuery.isXMLDoc( jQuery( "desc", svg )[ 0 ] ), "XML desc Element" ); assert.ok( jQuery.isXMLDoc( jQuery( "desc", svg )[ 0 ] ), "XML desc Element" );
} ); } );
QUnit.test( "isXMLDoc - falsy", function( assert ) {
assert.expect( 5 );
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( "XSS via location.hash", function( assert ) { QUnit.test( "XSS via location.hash", function( assert ) {
var done = assert.async(); var done = assert.async();
assert.expect( 1 ); assert.expect( 1 );