From fd421097c56696e4c1c4a99c1aae44c59a722be4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 7 Dec 2020 21:09:15 +0100 Subject: [PATCH] Core: Make jQuery.isXMLDoc accept falsy input Fixes gh-4782 Closes gh-4814 --- src/core.js | 4 ++-- test/unit/core.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index e122305ce..31d749dd1 100644 --- a/src/core.js +++ b/src/core.js @@ -307,8 +307,8 @@ jQuery.extend( { }, isXMLDoc: function( elem ) { - var namespace = elem.namespaceURI, - docElem = ( elem.ownerDocument || elem ).documentElement; + var namespace = elem && elem.namespaceURI, + docElem = elem && ( elem.ownerDocument || elem ).documentElement; // Assume HTML when documentElement doesn't yet exist, such as inside // document fragments. diff --git a/test/unit/core.js b/test/unit/core.js index e24966551..6bcea95af 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -417,6 +417,16 @@ QUnit.test( "isXMLDoc - XML", function( assert ) { 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 ) { var done = assert.async(); assert.expect( 1 ); -- 2.39.5